简体   繁体   中英

If an Object can hold an Array, how is the Array accessed?

I currently have an Object which holds a series of Arrays, when I do print_r it does show the arrays however, when I want to get these values out I seem to be getting an error.

print_r($Obj->Example);

Returns:

Object => Example ( 'Username' => 'Example' )

My code to query through the Object is:

foreach($Obj as $single):
    echo $Example['Username'];
endif;

Is it possible to query through like this because it isn't working and I get an error saying that:

$Obj is not defined as an Array

So how can I access the Example array and echo all the Usernames ?

As Example is an array that belongs to an object, the code would be like this

foreach($Obj->Example as $single):
    echo $single['Username'];
endif;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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