How can I convert an array like this to an object?
[128] => Array
(
[status] => "Figure A.
Facebook\'s horizontal scrollbars showing u
Here are three ways:
Fake a real object:
class convert
{
public $varible;
public function __construct($array)
{
$this = $array;
}
public static function toObject($array)
{
$array = new convert($array);
return $array;
}
}
Convert the array into an object by casting it to an object:
$array = array(
// ...
);
$object = (object) $array;
Manually convert the array into an object:
$object = object;
foreach ($arr as $key => $value) {
$object->{$key} = $value;
}