我怎样才能将这样的数组转换为对象?

  [128] => Array
        (
            [status] => Figure A.
 Facebook\'s horizontal scrollbars showing up on a 1024x768 screen resolution.
        )

    [129] => Array
        (
            [status] => The other day at work, I had some spare time
        )

)

 

这里有三种方法:一、伪造一个真实的物体:

class convert
{
    public $varible;

    public function __construct($array)
    {
        $this = $array;
    }

    public static function to ($array)
    {
        $array = new convert($array);
        return $array;
    }
}

 

二、通过将数组转换为对象将数组转换为对象:

$array = array(
    // ...
);
$  = ( ) $array;


三、手动将数组转换为对象:

$  =  ;
foreach ($arr as $key => $value) {
    $ ->{$key} = $value;
}
收藏 打印