0

试图访问此数组中的对象。我跟着

stdClass 对象 foreach PHP

无论我尝试什么,我都无法从阵列中得到我需要的东西。

唯一有效的是

 echo $response->TotalResults;

这给了我 18 的价值。很好,但是当我尝试时

  echo $response->Call[0]->ToNumber->_;

或者

 echo $response->Call->CallRecord->Result;

它返回空白

我已经尝试了另一个帖子中的 foreach 循环:

    foreach($responses->TotalResults as $value){
       foreach($value->Call as $obj){
         echo $obj->FromNumber;
        }
echo $value->name;
  }

什么都不返回。我真的没有在 php 网站上找到任何可以帮助指导我如何从这种数组中检索数据的东西。下面是数据的示例数组。

    object(stdClass)#8 (2) {
   ["TotalResults"]=> int(18)
   ["Call"]=>  array(18) {
        [0]=>
        object(stdClass)#9 (12) {
          ["FromNumber"]=>
          string(11) "17575551211"
          ["ToNumber"]=>
          object(stdClass)#10 (1) {
            ["_"]=>
            string(11) "17575554039"
          }
              ["State"]=>
              string(8) "FINISHED"
              ["BatchId"]=>
              int(33236)
              ["BroadcastId"]=>
              int(1069425001)
              ["ContactId"]=>
              float(836743)
              ["Inbound"]=>
              bool(false)
              ["Created"]=>
              string(20) "2013-08-09T15:24:11Z"
              ["Modified"]=>
              string(20) "2013-08-11T13:16:54Z"
              ["FinalResult"]=>
              string(2) "LA"
              ["id"]=>
              float(1001389)
       ["CallRecord"]=>
              array(2) {
            [0]=>
            object(stdClass)#11 (7) {
              ["Result"]=>
              string(2) "LA"
              ["FinishTime"]=>
              string(20) "2013-08-11T13:16:51Z"
              ["BilledAmount"]=>
              float(1.6667)
              ["QuestionResponse"]=>
              object(stdClass)#12 (2) {
                ["Question"]=>
                string(4) "Q1R1"
                ["Response"]=>
                string(7) "Confirm"
              }
              ["id"]=>
              float(572965)
              ["AnswerTime"]=>
              string(20) "2013-08-11T13:16:22Z"
              ["Duration"]=>
              int(29)
            }
            [1]=>
            object(stdClass)#13 (6) {
              ["Result"]=>
              string(6) "NO_ANS"
              ["FinishTime"]=>
              string(20) "2013-08-11T13:01:05Z"
              ["BilledAmount"]=>
              float(0)
              ["id"]=>
              float(57296503001)
              ["OriginateTime"]=>
              string(20) "2013-08-11T13:00:02Z"
              ["Duration"]=>
              int(0)
    }
  }
}
            [1]=>
            object(stdClass)#14 (12) {
              ["FromNumber"]=>
              string(11) "17575557998"
              ["ToNumber"]=>
              object(stdClass)#15 (1) {
                ["_"]=>
                string(11) "17575557255"
              }
              ["State"]=>
              string(8) "FINISHED"
              ["BatchId"]=>
              int(332369)
              ["BroadcastId"]=>
              int(1069425)
              ["ContactId"]=>
              float(83674367)
              ["Inbound"]=>
              bool(false)
              ["Created"]=>
              string(20) "2013-08-09T15:24:11Z"
              ["Modified"]=>
              string(20) "2013-08-11T13:03:17Z"
              ["FinalResult"]=>
              string(2) "LA"
              ["id"]=>
              float(100138916)
                ["CallRecord"]=>
          object(stdClass)#16 (6) {
            ["Result"]=>
            string(2) "LA"
            ["FinishTime"]=>
            string(20) "2013-08-11T13:03:13Z"
            ["BilledAmount"]=>
            float(5.0001)
            ["id"]=>
            float(57296546)
            ["AnswerTime"]=>
            string(20) "2013-08-11T13:00:35Z"
            ["Duration"]=>
            int(158)
          }
        }
        [2]=>
        object(stdClass)#17 (12) {
          ["FromNumber"]=>
          string(11) "17575557998"
          ["ToNumber"]=>
          object(stdClass)#18 (1) {
            ["_"]=>
            string(11) "17575552158"
          }
          ["State"]=>
          string(8) "FINISHED"
          ["BatchId"]=>
          int(332369)
          ["BroadcastId"]=>
          int(106942)
          ["ContactId"]=>
          float(83674)
          ["Inbound"]=>
          bool(false)
          ["Created"]=>
          string(20) "2013-08-09T15:24:11Z"
          ["Modified"]=>
          string(20) "2013-08-11T13:03:15Z"
          ["FinalResult"]=>
          string(2) "LA"
          ["id"]=>
          float(100138)

             }
          }
       }

关于如何访问数组的任何帮助都会很棒。问候

4

0 回答 0