如何通过省略一列来从多维数组中获取数据?

如何通过省略一列来从多维数组中获取数据?

问题描述:

I am storing info in an array in a loop like that:

while ($ind = mysql_fetch_array($result))
    $array["uniqueName"][$ind][$hash]["mac"] = $mac;

How can I get all $mac's if I am not given $hash, so by all hashes in context:

$array["uniqueName"][432][?]["mac"]

What can I do with '?' above? Can I omit that somehow?

我将信息存储在数组中,如下所示: p>

   while($ ind = mysql_fetch_array($ result))
 $ array [“uniqueName”] [$ ind] [$ hash] [“mac”] = $ mac; 
  code>  pre>  
 
 

如果我没有获得$ hash,我怎样才能得到所有$ mac?所以在上下文中的所有哈希值: p>

  $ array [“uniqueName”]  [432] [?] [“mac”] 
  code>  pre> 
 
 

我可以用'?'做什么? 以上? 我可以以某种方式省略吗? p> div>

you can loop over the hash keys like this:

$macs = array();
foreach($array["uniqueName"][$ind] as $hash){
    array_push($macs, $hash["mac"]);
}

Update from comment:

The foreach statement loads every key $array["uniqueName"][$id] contains into the $hash variable, one by one. So you don't have to know what these keys actually are (or even if there are any), you can just use them by referring to them using the $hash var. So in effect, that foreach statement loops over all keys $array["uniqueName"][$id] contains.