[solved]Array elements created twice
Posted: Wed Aug 03, 2005 11:44 am
Hi, I'm having a little trouble understanding why the following code:
Outputs:
And if I change one of the elements and output:
I get:
Is this the correct behaviour or am I doing something wrong? Should the numerical and string indexes be independent of each other?
Code: Select all
$foo=array("a" => 1, "b" => 2, "c" => 3);
foreach($foo as $key => $value)
{
echo "{$key} - {$value} <br>";
}Code: Select all
a - 1
b - 2
c - 3
0 - 1
1 - 2
2 - 3Code: Select all
$foo['a']=5;
foreach($foo as $key => $value)
{
echo "{$key} - {$value} <br>";
}Code: Select all
a - 5
b - 2
c - 3
0 - 1
1 - 2
2 - 3