【发布时间】:2014-04-28 17:04:33
【问题描述】:
这个答案可能看起来很简单,但我是 PHP 新手,花了太多时间试图弄清楚这一点。
我的数组如下所示:
$phone_number[] = array(
"type" => "home",
"value" => $customer_phone
);
我也有这个:
$customer = array(
"first_name" => $first_name,
"phone_numbers" => $phone_numbers,
"emails" => $emails,
我想检索每个客户的号码。我试过这个:
for ($j = 0; $j <= count($customer_entries) - 1; $j++) {
var_dump($customer_entries[$j]->phone_numbers->value);
}
但它给了我一个错误。它说我正在尝试获取非对象的属性,然后它说 null。
但是当我使用时:
var_dump($customer_entries[$j]->phone_numbers;
它给了我这样的东西:
array(1) {
[0]=>
object(stdClass)#744 (2) {
["type"]=>
string(4) "home"
["value"]=>
string(14) "(555) 555-5555"
}
}
如何让它只给我名为“value”的字符串的结果?
谢谢。
【问题讨论】:
-
首先,你说你有一个数组,但你试图将它作为一个对象来访问。其次,您有问题的数组名为
$customer,但在您的循环中,您尝试使用$customer_entries。