santa
santa

Reputation: 12512

Getting specific value from an array with PHP

If I have an array in the following format:

Array ( [0] => stdClass Object ( [id] => 1 [c] => 1 [q] => value 1. ) [1] => stdClass Object ( [id] => 2 [c] => 1 [q] => value 2...

and I need to get

value 1

Shouldn't I be able to get it by doing something like?

$myArray[0]['q']

FOr some reason I'm not getting anything...

Upvotes: 0

Views: 41

Answers (2)

Teena Thomas
Teena Thomas

Reputation: 5239

The element is inside an object, you need to do,

  echo $myArray[0]->q;

Upvotes: 2

Pitchinnate
Pitchinnate

Reputation: 7556

You need to use $myArray[0]->q it is an object not an array.

Upvotes: 2

Related Questions