0

I have a multidim array that I can view using print_r($users):

Array ( [0] => stdClass Object ( [username] => crustacea [created_on] => 2010-08-07 19:54:32 [active] => 1 ) ) 

I can also use print_r($users[0]). Since there's only one member in $users, the output looks somewhat the same.

I can't see how to retrieve the value crustacea. echo $users[0]['username']; doesn't do it. Examples I can find are echo $users['name_of_array']['username']; -- but I don't have a name of array to work with. How do I do it?

2 Answers 2

1

$user[0] is not an array but an object as indicated by [0] => stdClass Object.

echo $users[0]->username; 
Sign up to request clarification or add additional context in comments.

Comments

1

$user[0] is object and not an array. You can access your value by doing

$users[0]->username; 

Or you could cast/convert your object into an array like

((array)$users[0])['username']; 

1 Comment

I am accepting the other answer merely because it came in earlier. I appreciate the extra tip on casting as array. Thanks very much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.