开发者

Help with multidimensional Arrays in PHP

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
开发者_如何学JAVA121212
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 always 0.

You can get it via the foreach.

foreach($array_newbie as $key => $k) {
    echo $key . "\n";
}

Also, that array is an associative array, not a multi-dimensional array.

The latter is an array of whom their members are also arrays...

$arr = array(
   array(
      'a', 'b', 'c'
   ),
   array(
      'd', 'e', 'f'
   )
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜