douyan6958 2012-09-10 08:34
浏览 77
已采纳

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

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?

  • 写回答

1条回答 默认 最新

  • drvpvmz16241016 2012-09-10 08:39
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100