im trying to create an array from a loop in PHP.
I want the array to end up something like $array(100,100,100,100), this is my code:
$x = 0;
while($x < 5){
$array[$x] = 100;
$x++;
}
echo $array[0];
It outputs 1 instead of 100. Can someone tell me where i'm going wrong.
$arrayis empty before inserting the new values?for ($x = 0; $x < 5; $x++)since you know both the starting and ending values of$x. i.e. since you have a predetermined number of iterations.