Hi,
Was just playing around with arrays and watching the output as I use different methods to access them. When I use this code:
CODE
$prices = array('Tyres'=>100, 'Oil'=>10, 'SparkPlugs'=>4);
foreach ($prices as $key => $temp)
echo $key.'=>'.$temp.'<br />';
it produces this (expected) output
QUOTE
Tyres=>100
Oil=>10
SparkPlugs=>4
when I use this code:
CODE
$prices = array('Tyres'=>100, 'Oil'=>10, 'SparkPlugs'=>4);
while ($element = each($prices))
{
echo $element['key'];
echo ' - ';
echo $element['value'];
echo '<br />';
}
it produces this (expected) output:
QUOTE
Tyres - 100
Oil - 10
SparkPlugs - 4
but when I have both the code blocks on the one page, and only initialise the array once, it only produces the first output not both... In order to get both outputs I have have line one of both code blocks twice... is there a reason for this?
Cheers
This post has been edited by Study_Girl: 4 Jul, 2007 - 12:38 AM