douna5529 2010-12-17 01:59
浏览 139
已采纳

PHP搜索数组中的键并返回其值?

I would like to search key in multidimensional array and i would like to get corrosponding value associated with that key. For e.g. I would like to extract following texts from below array :

SENT AT 12.08ms

And the text

sample id 41962

following is an array print_r() output :

 Array
 (
      [0] => Array
                 (
                     [VERSION] => Array
                         (
                             [0] => Array
                                 (
                                     [group] => 
                                     [param] => Array
                                         (
                                         )

                                     [value] => Array
                                         (
                                             [0] => Array
                                                 (
                                                     [0] => 3.0
                                                 )

                                         )

                                 )

                         )

                     [SAMPLE] => Array
                         (
                             [0] => Array
                                 (
                                     [group] => 
                                     [param] => Array
                                         (
                                         )

                                     [value] => Array
                                         (
                                             [0] => Array
                                                 (
                                                     [0] => sample id 41962
                                                 )

                                         )

                                 )

                         )

                     [TSAM] => Array
                         (
                             [0] => Array
                                 (
                                     [group] => 
                                     [param] => Array
                                         (
                                         )

                                     [value] => Array
                                         (
                                             [0] => Array
                                                 (
                                                     [0] => sample group 141
                                                 )

                                             [1] => Array
                                                 (
                                                     [0] => ¯
                                                 )

                                             [2] => Array
                                                 (
                                                     [0] => sample batch 81
                                                 )

                                             [3] => Array
                                                 (
                                                     [0] => 
                                                 )

                                             [4] => Array
                                                 (
                                                     [0] => 
                                                 )

                                         )

                                 )

                         )

                     [STATUS] => Array
                         (
                             [0] => Array
                                 (
                                     [group] => 
                                     [param] => Array
                                         (
                                             [TYPE] => Array
                                                 (
                                                     [0] => CART
                                                 )

                                         )

                                     [value] => Array
                                         (
                                             [0] => Array
                                                 (
                                                     [0] => SENT AT 12.08ms
                                                 )

                                         )

                                 )

                         )

                 )
 )           

Can somebody provide me optimized code for above problem. The multidimensional array contains more than 5000 to 10000 arrays.

  • 写回答

3条回答 默认 最新

  • dongxian1699 2010-12-17 02:18
    关注

    If all the array keys have the same structure the following code should work:

    foreach($array as $item){
        $sentat = $item['STATUS'][0]['value'][0][0];
        $sample = $item['SAMPLE'][0]['value'][0][0];
    }
    

    More detailed information would help us to provide you more tips :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路