0

think I'm going mad but think i've tried everything possible!

got an object like so;

    object(stdClass)#9 (8) {
  ["Results"]=>
  array(3) {
    [0]=>
    object(stdClass)#10 (5) {
      ["EmailAddress"]=>
      string(22) "38ec95a@emailtests.com"
      ["Name"]=>
      string(13) "Daniel Crabbe"
      ["Date"]=>
      string(19) "2011-07-11 13:00:00"
      ["State"]=>
      string(6) "Active"
      ["CustomFields"]=>
      array(0) {
      }
    }
    [1]=>
    object(stdClass)#11 (5) {
      ["EmailAddress"]=>
      string(12) "dan@jynk.net"
      ["Name"]=>
      string(13) "Daniel Crabbe"
      ["Date"]=>
      string(19) "2011-10-11 12:43:00"
      ["State"]=>
      string(6) "Active"
      ["CustomFields"]=>
      array(0) {
      }
    }
    [2]=>
    object(stdClass)#12 (5) {
      ["EmailAddress"]=>
      string(23) "nikolaprice@hotmail.com"
      ["Name"]=>
      string(12) "Nicola Price"
      ["Date"]=>
      string(19) "2011-08-25 16:24:00"
      ["State"]=>
      string(6) "Active"
      ["CustomFields"]=>
      array(0) {
      }
    }
  }
  ["ResultsOrderedBy"]=>
  string(5) "email"
  ["OrderDirection"]=>
  string(3) "asc"
  ["PageNumber"]=>
  int(1)
  ["PageSize"]=>
  int(150)
  ["RecordsOnThisPage"]=>
  int(3)
  ["TotalNumberOfRecords"]=>
  int(3)
  ["NumberOfPages"]=>
  int(1)
}

and trying to loop through array(3) and get the email addresses with;

foreach($subscribed_result->results as $sr){
    $res++;
    echo $res.": ".$sr->EmailAddress." ".$sr['EmailAddress']." ";
}

and several variations but getting nowhere. what am into understanding?

Updates

this works better and can get the object from $sr as an array but still can't get $sr->emailAddress.

print $subscribed_result->response->Results[0]->EmailAddress; // works?

        foreach($subscribed_result->response->Results as $sr){
            echo $sr->EmailAdress."";   // doesn't work? 
            echo "<pre>";
            print_r($sr);
            echo "</pre>";
        }

spits out;

stdClass Object
(
    [EmailAddress] => 38ec95a@emailtests.com
    [Name] => Daniel Crabbe
    [Date] => 2011-07-11 13:00:00
    [State] => Active
    [CustomFields] => Array
        (
        )

)
4

1 回答 1

4

将其更改为:

foreach($subscribed_result->Results as $sr){
    $res++;
    echo $res.": ".$sr->EmailAdress;
}

注意Results代替resultsResults是一个对象,所以$sr['EmailAddress']不会工作。您只能像这样访问数组。$sr->EmailAddress将打印你想要的。

为了说明,这是您直接访问第一个电子邮件地址的方式:

print $subscribed_result->Results[0]->EmailAddress;
于 2011-10-11T12:19:00.513 回答