How to change stdClass object to array in PHP

If you have array like this


Array
(
[0] => stdClass Object
(
[page_id] => 269
)

[1] => stdClass Object
(
[page_id] => 887
)

[2] => stdClass Object
(
[page_id] => 544
)

)

Solution


$converted_arr = json_decode(json_encode($your_stdobj_array), true);

OR


foreach ($your_stdobj_arrayas $value){
$array[] = $value->page_id;
}

Leave a Reply

Your email address will not be published. Required fields are marked *