duanduan1993 2014-11-14 23:38
浏览 60
已采纳

PHP:从多维数组中提取值

In this array, I am attempting to extract the value int(2128) from the ["member_count"] key.

array(3) {
["total"]=>
int(1)
["data"]=>
  array(1) {
    [0]=>
      array(17) {
        ["id"]=>
      string(10) "999999999999"
        ["web_id"]=>
      int(421097)
        ["name"]=>
      string(21) "Name Of List"
        ["date_created"]=>
      string(19) "2014-07-14 13:51:01"
        ["email_type_option"]=>
      bool(false)
        ["use_awesomebar"]=>
      bool(true)
        ["default_from_name"]=>
      string(14) "Department Name"
        ["default_from_email"]=>
      string(24) "user@email.com"
        ["default_subject"]=>
      string(0) ""
        ["default_language"]=>
      string(2) "en"
        ["list_rating"]=>
      float(3.5)
        ["subscribe_url_short"]=>
      string(23) "website/4545"
        ["subscribe_url_long"]=>
      string(91) "website"
        ["beamer_address"]=>
      string(47) "key goes here"
        ["visibility"]=>
      string(3) "pub"
        ["stats"]=>
          array(16) {
            ["member_count"]=>
              int(2128)
            ["unsubscribe_count"]=>
              int(20)
            ["cleaned_count"]=>
              int(57)
            ["member_count_since_send"]=>
              int(1)
            ["unsubscribe_count_since_send"]=>
              int(9)
            ["cleaned_count_since_send"]=>
              int(29)
            ["campaign_count"]=>
              int(2)
            ["grouping_count"]=>
              int(1)
            ["group_count"]=>
              int(4)
            ["merge_var_count"]=>
              int(6)
            ["avg_sub_rate"]=>
              int(17)
            ["avg_unsub_rate"]=>
              int(3)
            ["target_sub_rate"]=>
              int(17)
            ["open_rate"]=>
              float(38.672399892502)
            ["click_rate"]=>
              float(14.932747735383)
            ["date_last_campaign"]=>
              string(19) "2014-11-07 19:14:30"
    }
    ["modules"]=>
       array(0) {
    }
  }
}
  ["errors"]=>
     array(0) {
  }
}

Here is the PHP that I have so far but I'm unable to get just the value "int(2128)"

  foreach($result as $row){
    foreach($row[0] as $row1){

   echo '<pre>';
   var_dump($row1['member_count']);
   echo '</pre>';
     }
  }

The Results I get:

string(1) "6"

NULL

string(1) "F"

string(1) "2"

NULL

NULL

string(1) "B"

string(1) "d"

string(0) ""

string(1) "e"

NULL

string(1) "h"

string(1) "h"

string(1) "u"

string(1) "p"

int(2128)

NULL

I greatly appreciate any help to narrow the results down to just the value "int(2128)".

Thanks.

  • 写回答

1条回答 默认 最新

  • dongliyu3278 2014-11-14 23:41
    关注

    If you only want the value 2128 use this:

    $array['data'][0]['stats']['member_count']
    

    ($array is the name of your multidimensional array)

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

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本