Can someone tell me what is the difference between these two loops / code snippets?
I get the same result, but the text book indicates that there is a difference with the outer and inner loop? Any clarification would be helpful. I don’t think I understand 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 />';
}
source
share