0

私は次のphpを持っています:

$getlists = new CS_REST_Campaigns($_POST['campaign_id'], $auth);
$getlistsresult = $wrap->get_lists_and_segments();

if($getlistsresult->was_successful()) {

   echo '<pre>';
    var_dump($getlistsresult->response);
    echo '</pre>';
}

上記の出力:

 object(stdClass)#310 (2) {
  ["Lists"]=>
  array(1) {
    [0]=>
    object(stdClass)#309 (2) {
      ["ListID"]=>
      string(32) "xxxxxxxxxxxxxxxxxxxxxx"
      ["Name"]=>
      string(6) "List 1"
    }
  }
  ["Segments"]=>
  array(0) {
  }
}

ListID をターゲット/抽出するにはどうすればよいですか?

何も返さない次のことを試しました:

foreach($getlistsresult->response->Results as $entry) {
    echo $entry->ListID;
}
4

4 に答える 4

3

foreach に間違いがあるようです:

foreach($getlistsresult->response->Lists as $entry) {
    echo $entry->ListID;
}
于 2013-07-16T10:23:06.180 に答える
2

Listsとして書いていResultsます。

foreach($getlistsresult->response->Lists as $entry) {
   echo $entry->ListID;
}
于 2013-07-16T10:22:28.773 に答える
1

直接:

echo $getlistsresult->response->Lists[0]->ListID

またはすべて:

foreach($getlistsresult->response->Lists as $entry) {
   echo $entry->ListID;
}
于 2013-07-16T10:24:02.430 に答える
0

型キャストを試す

$array   = (array)$getlistsresult->response
$array   = $array["Lists"]

 foreach($array as $value)
 {
    echo $value['ListID']
 }

またはオブジェクト反復を使用

$list   = $getlistsresult->response->Lists
foreach($list as $key=>$value)
{
    echo $value->ListId
 }
于 2013-07-16T10:24:19.633 に答える