dousha4804 2017-02-07 09:44
浏览 22

从Array中获取价值

I am trying to get a certain value out of an array. Example of the array is:

array(2) {
  ["error"]=>
  array(0) {
  }
  ["result"]=>
  array(1) {
    ["open"]=>
    array(1) {
      ["12345-AAAAA-66AAKK"]=>
      array(14) {
        ["inf"]=>

Usually when I want a certain value I would use:

$datawanted=$data[result][open][value];

However, in this case the first array is a variable that always changes (12345-AAAAA-66AAKK), I need to find the value of that.

I tried getting this with reset() and key[0] but this not give the wanted result.

Is there a way to get the output of the first element in the result array?

  • 写回答

2条回答 默认 最新

  • doubei2340 2017-02-07 09:50
    关注

    You can use array_search: http://php.net/manual/de/function.array-search.php

    Example:

    foreach ($array['result']['open'] as $dynamicKey => $item) {
        if ($key = array_search('Value you are looking for', $item) {
           $datawanted=$array['result']['open'][$dynamicKey][$key];
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口