Search code examples
phparraysobjectsoap-client

Accesing a Object array in PHP and convert it to Simple Array


I am trying to accessing a array, which is return by Soap class. But I am not able to iterate it. Please help. $server_output = curl_exec ($ch);

Variable $server_output has following return from Curl,

CalculatePremiumStructGeneratePolicyResponse Object
    (
        [GeneratePolicyResult] =&gt; <response><policyno></policyno><totalpremium>0</totalpremium><gc_customerid>100000000000192979</gc_customerid><transactionid>FT10317050001414</transactionid><errortext> Error In Proposal Creation. Error in User Entry:   
     Maximum Days For Past Policy Should Be 7</errortext></response>
        [result:CalculatePremiumWsdlClass:private] =&gt; 
        [lastError:CalculatePremiumWsdlClass:private] =&gt; 
        [internArrayToIterate:CalculatePremiumWsdlClass:private] =&gt; 
        [internArrayToIterateIsArray:CalculatePremiumWsdlClass:private] =&gt; 
        [internArrayToIterateOffset:CalculatePremiumWsdlClass:private] =&gt; 
    )

I want to convert above into simple array

 Array
    ( 
        [GeneratePolicyResult] =&gt; <response><policyno></policyno><totalpremium>0</totalpremium><gc_customerid>100000000000192979</gc_customerid><transactionid>FT10317050001414</transactionid><errortext> Error In Proposal Creation. Error in User Entry:   
     Maximum Days For Past Policy Should Be 7</errortext></response>
        [result] =&gt; 
        [lastError] =&gt; 
        [internArrayToIterate] =&gt; 
        [internArrayToIterateIsArray] =&gt; 
        [internArrayToIterateOffset] =&gt; 
    )

Please help!

Edit Note :- When I try to print gettype($server_output), it says its a string.


Solution

  • After a lot of try and solutions available on Stackflow, none of works, But When i check the type of variable, it was saying string.

    gettype($server_output) was printing string.

    So It was a string object. SoI decided to take it as string and try to parse it.

    $server_output = curl_exec ($ch);  
    $data = explode(" [GeneratePolicyResult] =>", $server_output); 
    $data = explode("[result:CalculatePremiumWsdlClass:private]", $data[1]); 
    

    And in this way,I have filter the "GeneratePolicyResult"