How to convert an array to object in PHP?

前端 未结 30 2862
说谎
说谎 2020-11-22 02:48

How can I convert an array like this to an object?

[128] => Array
    (
        [status] => "Figure A.
 Facebook\'s horizontal scrollbars showing u         


        
30条回答
  •  青春惊慌失措
    2020-11-22 03:14

    you can simply use type casting to convert an array to object.

    // *convert array to object* Array([id]=> 321313[username]=>shahbaz)
    $object = (object) $array_name;
    
    //now it is converted to object and you can access it.
    echo $object->username;
    

提交回复
热议问题