我已经完成了大部分的腿部工作。我已经连接到API并且它返回了一系列客户对象,我正在努力解决如何遍历每个客户对象。
以下是API调用返回的结构:
stdClass Object
(
[Customer] => Array
(
[0] => stdClass Object
(
[CustomerID] => 20409125
[Name] => Computer Says No
[Telephone] =>
[Mobile] =>
[Email] => myemail@address.com
[Website] =>
)
[1] => stdClass Object
(
[CustomerID] => 20409126
[Name] => Joe Bloggs
[Telephone] =>
[Mobile] =>
[Email] => myemail@address.com
[Website] =>
)
[3] => stdClass Object
(
[CustomerID] => 20409127
[Name] => Jane Bloggs
[Telephone] =>
[Mobile] =>
[Email] => myemail@address.com
[Website] =>
)
)
)
以下是我试图循环回复的方法
$kashflow = new Kashflow('my username','my password');
$customers = $kashflow->getCustomers();
foreach($customers as $customer){
echo "<pre>";
print_r($customer->CustomerID);
echo "</pre>";
}
如果我print_r($customers)
我得到了:
stdClass Object
(
[GetCustomersResult] => stdClass Object
(
[Customer] => Array
(
[0] => stdClass Object
(
[CustomerID] => 20409125
)
[1] => stdClass Object
(
[CustomerID] => 20409126
)
[2] => stdClass Object
(
[CustomerID] => 20409127
)
)
)
)
答案 0 :(得分:0)
试试这个:
$kashflow = new Kashflow('my username','my password');
$customers = $kashflow->getCustomers();
foreach($customers->GetCustomersResult->Customer as $customer){
echo "<pre>";
print_r($customer->CustomerID);
echo "</pre>";
}
答案 1 :(得分:0)
你正在获得像
这样的记录 $first_id= array_column($customers, 'cust_id');
foreach($first_id as $id)
{
echo "<pre>";
echo $id;
echo "</pre>"
}