Question

I have the following 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>';
}

The above outputs:

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

How would i target / extract the ListID?

I have tried the following which doesnt return anything:

foreach($getlistsresult->response->Results as $entry) {
    echo $entry->ListID;
}
Was it helpful?

Solution

Looks like there's a mistake in your foreach:

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

OTHER TIPS

You are writing Lists as Results.

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

directly by:

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

or all:

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

Try type casting

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

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

or use object Iteration

$list   = $getlistsresult->response->Lists
foreach($list as $key=>$value)
{
    echo $value->ListId
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top