There is nothing special with array_push in loop (You are using while loop) and initilizing values to an array ($arr[] = $element
). The only differene is you are pushing value into the array through while loop and declaring initially using assignment operator.
In your case, you have initilized $element to the array
$arr[] = "123"; //Lets say 123 is $element
$arr[] = "NAME"; //Same way, you can repeat in next line as well
$arr[] = "45";
echo '<pre>';
print_r($arr);
// And the output was
Array (
[0] => 123
[1] => NAME
[2] => 45
)
And the next statement was
while ($row = $result->fetch_assoc())
{
$ids[] = $row['id'];// Lets say 123 is $row['id'];
$names[] = $row['name']; //Lets say NAME is $row['name'];
$ages[] = $row['age']; //Lets say 45 is $row['age'];
}
//The output will be same if only one row exist in the loop
Array (
[0] => 123
[1] => NAME
[2] => 45
.................. // Based on while loop rows
)
The symbol [] will push value into array because you didn't mention any key in between bracket.