Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 数组中的stsClass对象_Arrays_Stdclass_Control Structure - Fatal编程技术网

Arrays 数组中的stsClass对象

Arrays 数组中的stsClass对象,arrays,stdclass,control-structure,Arrays,Stdclass,Control Structure,我var\u转储了一个变量,得到了这个,我怎样才能正确地显示它 比如, 名称: 国家: <?php array(3) { [0]=> object(stdClass)#19 (3) { ["Firstname"]=> string(4) "John" ["Lastname"]=> string(4) "Le

var\u转储了一个变量,得到了这个,我怎样才能正确地显示它

比如,
名称:
国家:

 <?php
 array(3) { 
        [0]=> object(stdClass)#19 (3) { 
                                    ["Firstname"]=> string(4) "John"
                                    ["Lastname"]=> string(4) "Lest"
                                    ["Country"]=> string(3) "USA" 
                                    }
        [1]=> object(stdClass)#20 (3) {
                                    ["Firstname"]=> string(5) "Larry" 
                                    ["Lastname"]=> string(4) "Jems" 
                                    ["Country"]=> string(6) "Canada" 
                                    } 
        [2]=> object(stdClass)#21 (3) { 
                                    ["Firstname"]=> string(3) "Jim"
                                    ["Lastname"]=> string(5) "Ricks" 
                                    ["Country"]=> string(7) "England" 
                                    }
    }
 ?>

stdClass
是一种匿名对象。Firstname、Lastname和Country是属性。要访问它们:

echo $obj->Firstname

当i
echo$results[0]->$obj->$Firstname时,stdClass对象位于数组中,它表示未定义的变量,实际上我需要遍历所有这些对象。@NestedWeb:try
echo$results[0]->Firstname
。如果您无法使循环从那里开始工作,您应该返回并重新阅读PHP手册。@NestedWeb
$obj
只是一个示例,因为您没有提供实际的变量名。