PHP引用嵌套数组值 [英] PHP referencing nested array values
本文介绍了PHP引用嵌套数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法从嵌套数组中返回值...
I'm having trouble returning a value out of a nested array...
数组转储看起来像这样
object(myObj)#1 (3) {
["thing1"]=> string(5) "abcde"
["thing2"]=> string(2) "ab"
["data"]=> array(3) {
[0]=> string(3) "370"
["id"]=> string(3) "370"
[1]=> string(26) ""
["name"]=> string(26) "abcdefghijklmnopqrstuvwxyz"
[2]=> string(0) ""
["address"]=> string(0) ""
[3]=> string(4) "wxyz"
["email"]=> string(4) "wxyz"
}
我想在其中获得名称 数据数组。...
I want to get to "name" inside the "data" array....
我已经尝试
echo $myObj['data']['name'];
还
echo $myObj -> $data -> $name;
它们始终以未定义状态返回。
they always come back as UNDEFINED.
推荐答案
使用
$myObj -> data['name'];
这肯定令人困惑。让我解释一下。
It sure is confusing. Let me explain.
您看到的 var_dump
结果有两个部分,一个是对象转储,另一个是数组。
The var_dump
result you saw has two parts on them, one is object dump and another array .
object(myObj)#1 (3) { <-- Starting point of object
["thing1"]=> string(5) "abcde" <-- This is a property which has string value
["thing2"]=> string(2) "ab" <-- This is a property which has string value
"data" here is a property of
object so you have to use
$myObj -> data to access it
["data"]=> array(3) { <-- But this is an array so you have to use
data[] to access its value
[0]=> string(3) "370"
["id"]=> string(3) "370"
[1]=> string(26) ""
["name"]=> string(26) "abcdefghijklmnopqrstuvwxyz"
[2]=> string(0) ""
["address"]=> string(0) ""
[3]=> string(4) "wxyz"
["email"]=> string(4) "wxyz"
}
这篇关于PHP引用嵌套数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文