How to convert an array to object in PHP?

前端 未结 30 2813
说谎
说谎 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:03

    There's no built-in method to do it as far as I'm aware, but it's as easy as a simple loop:

        $obj= new stdClass();
    
        foreach ($array as $k=> $v) {
            $obj->{$k} = $v;
        }
    

    You can expound on that if you need it to build your object recursively.

提交回复
热议问题