mysql - Cannot access PHP Object as Array -
i facing unusual problem. may silly mistake, , missing basics.
i'm running php 5.6.1 on mamp.
i have simple array mysql query. using foreach
loop, can print_r()
each value, gives me: stdclass object ( [srno] => 6 [link] => this-is-link )
now can echo $obj->srno
, , prints fine. can't utilize echo $obj['srno']
using, on older version of php, but- shows nothing.
any help appreciated. thanks!
if have stdclass
object , need address array, can cast array quite easily:
$someobj = new stdclass(); $someobj->foo = "bar"; $somearray = (array)$someobj; // cast object array echo $somearray['foo']; // give "bar"
working example: http://3v4l.org/nni1y
of course of study comments pointed out, may want @ retrieving mysql results array in first place.
php mysql arrays
No comments:
Post a Comment