dst3605528 2014-12-09 21:28 采纳率: 0%
浏览 16

数组搜索,而不是多次打印ket值

I used foreach to print all keys and values. "$devicename_key" is printing the key which is fine but "$devicetype_key" is not printing. I see the value of 129 exist in array.

I have array with id in one row and value in next, its coming from database and I was able to clean it up in something like this. If there is another way to do this, please feel free to tell me.

I am getting the key for 128 adding 1 to it and then printing the value of 128. 129 is not printing.

Key=0, Value=:128
Key=1, Value=:TCM-7811
Key=2, Value=:129
Key=3, Value=:2
Key=4, Value=:130
Key=5, Value=:3

    foreach($extrafield_info as $x => $x_value) {
        echo "Key=" . $x . ", Value=" . $x_value;
       echo "<br>";
    }
    // device name  128
    $deviceid_key = array_search('128', $extrafield_info);
    //echo 'device id key is ' . $deviceid_key;
    $devicename_key = $deviceid_key +1 ;
    //echo 'device key is ' . $devicename_key;

    // device type 129
    if (array_key_exists('129', $extrafield_info)) {
        $devicetype_key = array_search('129', $extrafield_info);
        echo 'key is ' . $devicetype_key;
    }
  • 写回答

2条回答 默认 最新

  • drau89457 2014-12-09 21:45
    关注

    You are doing array_key_exists in your final if check, but 129 is not the key, it is the value.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比