0

I've got this code

$vote = array(
    $arrayName[0][firstsector],
    $termin[1][firstsector],
    $termin[2][firstsector],
    $termin[3][firstsector]
);

Now I want to create a loop for it. I tried this:

$howMuchIneed = 5;

for ($x = 0; $x <= $howMuchIneed; $x++) {
    $vote = array(
        $arrayName[$x][firstsector]
    );
}

But the result doesn't look the same as the first code.

1
  • becuase you storing the value in $vote which is not an array Commented Oct 13, 2015 at 9:09

2 Answers 2

1

Have you tried this ?

for ($x = 0; $x <= $howMuchIneed; $x++) {
    array_push($vote, $arrayName[$x][firstsector]);
}

initializes Array

$vote = array();

If you want to learn more about array_push http://php.net/manual/en/function.array-push.php

Sign up to request clarification or add additional context in comments.

Comments

0

Try this (in your for loop):

$vote[] = $arrayName[$x]['firstsector'];

... and don't forget to declare your array before your loop!

$vote = array();

And in your first example you have 4 elements, condition in your for should be $x < 4 - arrays in PHP are zero-based.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.