Can someone tell me what the difference between these two loops / code snippets are?
I am getting the same output, but a text book is indicating there is a difference with the outer and inner loop? Any clarification would be helpful. I don't think I am understanding the list with each function.
Array definition:
$newArray = array(array('CODE' => 'TIR', 'Description' =>'TIRES', 'Price' => 100),
array('CODE' => 'OIL', 'Description' => 'Oil', 'Price' =>10),
array('CODE' => 'SPK', 'Description' => 'Spark Plug', 'Price' =>40)
);
Code snippet 1:
for ($row = 0; $row < 3; $row ++)
{
echo ' |'.$newArray[$row]['CODE'].'| '.$newArray[$row]['Description']. '| '.$newArray[$row]['Price'];
echo '<br />';
echo '<br />';
}
Code snippet 2:
for ($row =0; $row <3; $row ++)
{
while (list($key, $value) = each ($newArray[$row]))
{
echo "|$value";
}
echo '<br />';
echo '<br />';
}
"another element" => "Will only be shown by the second code snippet"