Return PHP object by index number (not name)

后端 未结 5 805
不思量自难忘°
不思量自难忘° 2020-11-30 08:13

Goal: retrieve an element of data from within a PHP object by number.

This is the print_r($data) of the object:

stdClass Object
(
    [0] => stdCl         


        
5条回答
  •  天涯浪人
    2020-11-30 08:46

    try this:

    echo $data[0]['UserName'];
    

    According to the manual, objects are not meant to be used that way. The comments on this page do provide a way around if that's a must-have for you. You could also simply rely on arrays if you are just using the object for properties (and not behaviours).

提交回复
热议问题