Hi

Can anyone tell me if there is an easy way to convert an object into an array.

I currently have the following object:-

PHP Code:
stdClass Object
(
    [
documentFiltering] => 
    [
searchComments] => 
    [
estimatedTotalResultsCount] => 17900000
    
[estimateIsExact] => 
    [
resultElements] => Array
        (
            [
0] => stdClass Object
                
(
                    [
summary] => 
                    [
URL] => http://www.test.com/
                    
[snippet] => Provides extranet privacy to clients making a range of <b>tests</b> and surveys available <br>  to their human resources departmentsCompanies can <b>test</bprospective and <b>...</b>
                    [
title] => <b>Test</bCentral Home
                    
[cachedSize] => 39k
                    
[relatedInformationPresent] => 1
                    
[hostName] => 
                    [
directoryCategory] => stdClass Object
                        
(
                            [
fullViewableName] => 
                            [
specialEncoding] => 
                        )

                    [
directoryTitle] => 
                )

            [
1] => stdClass Object
                
(
                    [
summary] => 
                    [
URL] => http://www.bandwidthplace.com/speedtest/
                    
[snippet] => Personal <b>Test</b>. <b>Test</bthe speed of your Internet connection Free up to 3 times a <br>  month Purchase a subscription for. Up to 1000 <b>tests</bper monthPersonal <b>test</b> <b>...</b>
                    [
title] => Bandwidth Speed <b>Test</b>
                    [
cachedSize] => 15k
                    
[relatedInformationPresent] => 1
                    
[hostName] => 
                    [
directoryCategory] => stdClass Object
                        
(
                            [
fullViewableName] => 
                            [
specialEncoding] => 
                        )

                    [
directoryTitle] => 
                )

            [
2] => stdClass Object
                
(
                    [
summary] => 
                    [
URL] => http://www.innergeek.us/geek.html
                    
[snippet] => Geeks everywhere have taken the Original Geek <b>Test</b>, a comprehensive 507-point <br>  survey of how geeky you arePossible ranks include Geekish TendenciesGeek, <b>...</b>
                    [
title] => Geek Out with the Original Geek <b>Test</b>
                    [
cachedSize] => 10k
                    
[relatedInformationPresent] => 1
                    
[hostName] => 
                    [
directoryCategory] => stdClass Object
                        
(
                            [
fullViewableName] => 
                            [
specialEncoding] => 
                        )

                    [
directoryTitle] => 
                )

        )

    [
searchQuery] => test
    
[startIndex] => 1
    
[endIndex] => 3
    
[searchTips] => 
    [
directoryCategories] => Array
        (
        )

    [
searchTime] => 0.026511

As you can see the object contains various items some of which are arrays, I wish the objects within these arrays to be converted into arrays as well (ie it should recursively go through all arrays and objects and convert the content into arrays if need be).

I have created the following code:-

PHP Code:
function object_2_array($result)
{
    
$array = array();
    foreach (
$result as $key=>$value)
    {
        if (
is_object($value))
        {
            
$array[$key]=object_2_array($value);
        }
        if (
is_array($value))
        {
            
$array[$key]=object_2_array($value);
        }
        else
        {
            
$array[$key]=$value;
        }
    }
    return 
$array;

but it does not convert the objects within the array probably for some silly reason that I cannot currently see.