我有以下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;
}
答案 0 :(得分:3)
看起来你的foreach有一个错误:
foreach($getlistsresult->response->Lists as $entry) {
echo $entry->ListID;
}
答案 1 :(得分:2)
您正在将Lists
写为Results
。
foreach($getlistsresult->response->Lists as $entry) {
echo $entry->ListID;
}
答案 2 :(得分:1)
直接通过:
echo $getlistsresult->response->Lists[0]->ListID
或全部:
foreach($getlistsresult->response->Lists as $entry) {
echo $entry->ListID;
}
答案 3 :(得分: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
}