foreach, I don't get this one?
Posted: Sun May 25, 2003 5:20 am
This is my array
then I have the following foreach loop
which produces the following result
100=>
10=>
4=>
If I add the $value variable
my result becomes
tires=>100
oil=>10
spark plugs=>4
I'm not specifying a variable of $value anywhere so does php understand this?
If it does then again why does $key become the value if I don't specify =>value as per the first set of code?
Code: Select all
$pricesї'tires']=100;
$pricesї'oil']=10;
$pricesї'spark plugs']=4;Code: Select all
foreach ($prices as $key )
echo $key.'=>'.$value.'<br/>';which produces the following result
100=>
10=>
4=>
If I add the $value variable
Code: Select all
foreach ($prices as $key => $value)
echo $key.'=>'.$value.'<br/>';tires=>100
oil=>10
spark plugs=>4
I'm not specifying a variable of $value anywhere so does php understand this?
If it does then again why does $key become the value if I don't specify =>value as per the first set of code?