[英]PHP cannot access object in array
in my application i get returned an array of objects and i am trying to access to access the object inside the array like this $array[0]->name
but it doesn't work for some reason , 在我的应用程序中,我返回了一个对象数组,我试图访问该数组中的对象,例如$array[0]->name
但是由于某种原因它不起作用,
i tried to access it like this - $var = $array[0]; $var->name
我试图这样访问它- $var = $array[0]; $var->name
$var = $array[0]; $var->name
and it shows me this error > Trying to get property of non-object
$var = $array[0]; $var->name
,它向我显示此错误> Trying to get property of non-object
whats going on here ? 这里发生了什么 ? why i cant access the object ? 为什么我无法访问该对象? and how can i access it ? 以及我如何访问它? also , would be better if i just got a multidimensional array instead array of objects? 还,如果我只是得到一个多维数组而不是对象数组会更好吗?
var_dump:// var_dump://
array(2) {
[0]=>
object(stdClass)#16 (9) {
["id"]=>
string(1) "1"
["name"]=>
string(27) "нямам си и идея"
["description"]=>
string(19) "емиииии....."
["price"]=>
string(3) "823"
["lang"]=>
string(2) "bg"
["category"]=>
string(1) "0"
["slug"]=>
string(7) "shalala"
["status"]=>
string(1) "1"
["sid"]=>
string(1) "1"
}
[1]=>
object(stdClass)#17 (9) {
["id"]=>
string(1) "2"
["name"]=>
string(19) "no tyore idea what "
["description"]=>
string(22) "are you talking to me "
["price"]=>
string(3) "823"
["lang"]=>
string(2) "en"
["category"]=>
string(1) "0"
["slug"]=>
string(7) "shalala"
["status"]=>
string(1) "1"
["sid"]=>
string(1) "1"
}
}
vardump of $array[0] $ array的容器[0]
object(stdClass)#16 (9) {
["id"]=>
string(1) "1"
["name"]=>
string(27) "нямам си и идея"
["description"]=>
string(19) "емиииии....."
["price"]=>
string(3) "823"
["lang"]=>
string(2) "bg"
["category"]=>
string(1) "0"
["slug"]=>
string(7) "shalala"
["status"]=>
string(1) "1"
["sid"]=>
string(1) "1"
}
[resolved] = the framework was pointing me at the wrong line of code the error was 10 lines down the code and i didnt see it :( [已解决] =框架将我指向错误的代码行,错误是代码向下10行,我没有看到它:(
The issue is somewhere else. 问题出在别的地方。
The $array[0]
is NOT an object that's why it's saying Trying to get property of non-object
. $array[0]
不是对象,这就是为什么要Trying to get property of non-object
的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.