0

嗨,大家一直在尝试为这个数组找到解决方案,但我不确定这个数组的术语是什么

我有这个

$arraylist = 
Array ([0] => Array ([ID] => 123
                       [No] => 5 
                       [CLASS] => B)
       [1] => Array ([ID] => 456
                       [No] => 6 
                       [CLASS] => B)
)

echo $arraylist[0]['ID']得到 123 我怎样才能得到 ID 而不是它的值

4

2 回答 2

4
$keys = array_keys($array[0]);
echo $keys[0];
于 2012-08-23T03:53:06.060 回答
2

您可以通过以下方式遍历数组:

//go over array 0 and array 1
foreach($arraylist as $arr){
  //go over ID, NO, CLASS
  foreach($arr as $key => $val){
    //here the first $key = 'ID' and first $val = 123
    // the second pass in the loop will have $key = 'No' and $val = 5
    // and so on.
    // so you can do whatever you want with it here
    //...
  }
}
于 2012-08-23T04:01:51.347 回答