How can I get the key and the value ? I tried using key() but it didn’t work:
$array_newbie = array();
$array_newbie['121412'] = "Hello";
$array_newbie['121212'] = "Noob";
$array_newbie['155161'] = "nabbaa";
foreach($array_newbie as $k)
{
echo key($array_newbie) . "\n";
}
this outputs:
121212
121212
121212
how can I get the key value ? I want it to output
121412
121212
155161
i’m new to php and having trouble with this multi dimensional arrays, thanks
key()is getting the key of the current array pointer. In your case, it is always0.You can get it via the
foreach.Also, that array is an associative array, not a multi-dimensional array.
The latter is an array of whom their members are also arrays…