简体   繁体   English

PHP:数组内部对象内部数组内部的访问元素

[英]PHP: Access element inside array inside object inside array

I would like to know the right syntax to target an element inside an array inside an object inside an array. 我想知道正确的语法以数组内的对象内的数组内的元素为目标。

If I do a var_dump on the $result array, it looks like: 如果我在$result数组上执行var_dump,则如下所示:

array(1) {
  [0]=>
  object(stdClass)#8626 (10) {
    ["id"]=> string(2) "24"
    ["fname"]=> string(4) "firstname"
    ["lname"]=> string(10) "lastname"
    ["email"]=> string(14) "email@gmail.com"
    ["personnummer"]=> string(5) "66655"
    ["snailmail"]=> string(1) "1"
    ["lineage_nr"]=> string(1) "6"
    ["payed"]=> string(1) "0"
    ["belong_to_lineage"]=> string(1) "1"
    ["lineage_name"]=> string(0) ""
  }
}

How would I get the value of the element " payed "? 我如何获得“已支付 ”元素的值?

It requires more than: $result[0]->payed .. 它需要的不止是: $result[0]->payed ..

I had this line of code: 我有这行代码:

echo "<h1> PAYED has the value: " . $result[0]->payed . "</h1>";

And it resulted in : 结果是:

"Trying to get property of non-object" 

Edit : Bad mistake - the results of the query was empty , that's why I couldn't target "$result[0]->payed" (it didn't exist). 编辑 :严重错误-查询的结果为空,这就是为什么我无法定位“ $ result [0]-> payed”(它不存在)的原因。

Here is a proof of concept of how it works. 这是其工作原理的概念证明。 What makes you think it doesnt? 是什么让您认为它没有? (not trying to sound snarky) Are you referencing it correctly? (不要听起来很nar亵)您是否正确引用了它?

$obj = array(new stdClass());
$obj[0]->firstName = "NAME!";
var_dump($obj);
echo $obj[0]->firstName;

Echoes: 回声:

array(1) {
  [0]=>
  object(stdClass)#1 (1) {
    ["firstName"]=>
    string(5) "NAME!"
  }
}
NAME!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM