0

I am getting values from mysql query as an object so I checked with print_r($result); and got like this

stdClass Object
(
    [user_name] => user1,user2,user3,user4
)

if I try to do like this

echo $result['user_name']; 

then getting error

"Cannot use object of type stdClass as array"

what should be the correct way to echo user1,user2,user3 values

1
  • 1
    try echo $result->user_name Commented Jan 13, 2019 at 10:14

1 Answer 1

1

When you get an array of objects

stdClass Object
(
    [user_name] => user1,user2,user3,user4
)

then try to show data like this

echo $result->user_name;

When associative array without objects

Array ( [user_name] => user1, user2, user3, user4 )

Do like this

echo $result['user_name'];
Sign up to request clarification or add additional context in comments.

1 Comment

@Anonymous your welcome. Accept the answer if it suits you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.