我正在搜索一个返回多个条目的数据库,但我不知道如何查询返回的数据?
搜索最多可返回20个结果(虽然这不太可能)返回数组的示例如下:
RESPONSE: relationships/search Array
(
[0] => stdClass Object
(
[relationship_id] => 1487400
[legal_form] => Sole Trader
[display_name] => Jones Jones t/a
[relationship_status] => Prospect: Hot
[telephone_number] => 02075387446
[telephone_number_2] =>
[mobile_number] =>
[email_address] => smith@smith.com
[date_of_birth] =>
[registration_number] =>
[vat_registration_number] =>
[postcode] =>
[creation_date] => 2017-09-14
)
[1] => stdClass Object
(
[relationship_id] => 1487399
[legal_form] => Sole Trader
[display_name] => Smith Smith t/a
[relationship_status] => Prospect: Hot
[telephone_number] => 02087653458
[telephone_number_2] =>
[mobile_number] =>
[email_address] => smith@smith.com
[date_of_birth] =>
[registration_number] =>
[vat_registration_number] =>
[postcode] =>
[creation_date] => 2017-09-14
)
)
有人可以提供任何建议吗?
修改
我觉得我有点傻,因为我无法弄清楚我需要做些什么来访问每个密钥中的objects
?
继承我的代码:
$relationship = postRequest('relationships/search', array('mobile_number' => $phone, 'email_address'=>$email, 'return_multiple_flag'=>Y));
if(isset($relationship->relationship_id))
foreach ($relationship as $object) {
if($object->object_property == $phone && $email && $email != 'none@none.com'){
return $relationship->relationship_id;
}elseif($object->object_property == $phone){
return $relationship->relationship_id;
}elseif($object->object_property == $email && $email != 'none@none.com'){
return $relationship->relationship_id; };
};
我知道foreach
错了。
答案 0 :(得分:2)
您有一组stdClass
个对象。
您可以通过数字键访问它们,从0开始:
$obj = $array[0]; // First element in the array
或者,你可以循环使用它们:
foreach ($array as $obj) {
// code here
}
您可以使用->
运算符访问对象的属性:
$id = $obj->relationship_id;
希望这有帮助!