consider the following array
$arr1=array('a'=>2,'b'=>22,'c'=>4,'d'=>10)
Now,for
print_r(array_keys($arr1));
output is
Array ( [0] => a [1] => b [2] => c [3] => d )
Fine because return type of array_keys is array.
Even echo array_keys($arr1);
gives Array
as output.
But,for
foreach(array_keys($arr1) as $key)
{
echo $key.'<br/>';
}
output is abcd
Can someone explain how foreach
is working here as i was expecting the following output
[a] => 2
[b] => 22
[c] => 4
[d] => 10
Do not want a better code so as to display my expected output.Just want to know how foreach is looping in this case.