How To Change Object Into Array in PHP
Posted by in PHPHi Friends, When I was working with one wordpress project I got one object array by get_posts method, But I want array instead of object array. So i search a lot for it and i found so many solutions and then finally i create one funtion in which you have to pass object only and it will return array from that object. So below is the function by which you can get array from that object.
<?php
function objectToArray( $objecttemp )
{
foreach($objecttemp as $object)
{
if( !is_object( $object ) && !is_array( $object ) )
{
return $object;
}
if( is_object( $object ) )
{
$object = get_object_vars( $object );
}
$lastarray[] = $object;
//return array_map( 'objectToArray', $object );
}
return $lastarray;
}
?>
Try to use it and if you cant understand it or not able to make it work then you can contact me.
Also I am Freelance PHP Developer having more than 3 years of experience, So if you want to do any projects then you can contact me.
Related Posts :
You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.




