title: Customize array from cURL XML response
body: <p>I need to output an array with a specif format from a cURL request. I tried many ways to format the XML result as needed without luck.</p>
  
  <p>Here's the PHP code</p>
  
  <pre><code>&lt;?php
  $request_url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?nCdEmpresa=&amp;sDsSenha=&amp;sCepOrigem=71939360&amp;sCepDestino=72151613&amp;nVlPeso=1&amp;nCdFormato=1&amp;nVlComprimento=16&amp;nVlAltura=5&amp;nVlLargura=15&amp;sCdMaoPropria=s&amp;nVlValorDeclarado=200&amp;sCdAvisoRecebimento=n&amp;nCdServico=41106%2C40045&amp;nVlDiametro=0&amp;StrRetorno=xml 4110616,9034,000,001,50SN04004519,2014,000,002,00SS0";
  
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $request_url);
  curl_setopt($curl, CURLOPT_TIMEOUT, 130);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  
  $response = curl_exec($curl);
              curl_close($curl);    
  
  print_r($response);
  ?&gt;
  </code></pre>
  
  <p>It prints the following XML</p>
  
  <pre><code>&lt;servicos&gt;
      &lt;cservico&gt;
          &lt;codigo&gt;41106&lt;/codigo&gt;
          &lt;valor&gt;16,90&lt;/valor&gt;
          &lt;prazoentrega&gt;3&lt;/prazoentrega&gt;
          ...
          &lt;erro&gt;0&lt;/erro&gt;
          &lt;msgerro&gt;
          &lt;/msgerro&gt;
      &lt;/cservico&gt;
      &lt;cservico&gt;
          &lt;codigo&gt;40045&lt;/codigo&gt;
          &lt;valor&gt;19,20&lt;/valor&gt;
          &lt;prazoentrega&gt;1&lt;/prazoentrega&gt;
          ...
          &lt;erro&gt;0&lt;/erro&gt;
          &lt;msgerro&gt;
          &lt;/msgerro&gt;
      &lt;/cservico&gt;
  &lt;/servicos&gt;
  </code></pre>
  
  <p>Or the following array if I apply <code>$xml = new SimpleXMLElement($response);</code></p>
  
  <pre><code>SimpleXMLElement Object
  (
      [cServico] =&gt; Array
          (
              [0] =&gt; SimpleXMLElement Object
                  (
                      [Codigo] =&gt; 41106
                      [Valor] =&gt; 16,90
                      [PrazoEntrega] =&gt; 3
                      ...
                      [Erro] =&gt; 0
                      [MsgErro] =&gt; SimpleXMLElement Object
                          (
                          )
                  )
              [1] =&gt; SimpleXMLElement Object
                  (
                      [Codigo] =&gt; 40045
                      [Valor] =&gt; 19,20
                      [PrazoEntrega] =&gt; 1
                      ...
                      [Erro] =&gt; 0
                      [MsgErro] =&gt; SimpleXMLElement Object
                          (
                          )
                  )
          )
  )
  </code></pre>
  
  <p>What I need to return is and Array like this. I tried almost every method found in other questions here but never got a good way to construct this two-dimension array.</p>
  
  <pre><code>array(
      'Option Name' =&gt; array(
         'id'=&gt;'40045',
         'quote'=&gt;'20,20',
         'days'=&gt;'1',
      ),
      'Option Name' =&gt; array(
         'id'=&gt;'40215',
         'quote'=&gt;'29,27',
         'days'=&gt;'3',
      )
  ) 
  </code></pre>
  
  <p>*Option Name will be retrieved afterwards by ID code.</p>