How to extract index data from this array?

-1

I'm developing a real estate site and I'll use the REST feature. The code below returns me one by one the properties registered in the server software as can be seen here > .

$dados = array( 
    'fields'    => 
        array( 
            'Codigo', 'Cidade', 'Bairro', 'ValorVenda' 
    ), 
    'paginacao' =>  
        array( 
            'pagina'        => 1, 
            'quantidade'    => 10 
    ) 
); 

$key         =  'c9fdd79584fb8d369a6a579af1a8f681'; 
$postFields  =  json_encode( $dados ); 
$url         =  'http://sandbox-rest.vistahost.com.br/imoveis/listar?key=' . $key; 
$url        .=  '&showtotal=1&pesquisa=' . $postFields; 

$ch = curl_init($url); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 
curl_setopt( $ch, CURLOPT_HTTPHEADER , array( 'Accept: application/json' ) ); 
$result = curl_exec( $ch ); 

$result = json_decode( $result, true ); 

echo '<pre>'; 
    print_r( $result ); 
echo '<pre>';

My question is: in this case, how do you extract one-by-one data from real estate arrays as indexes?

What I do know is that $result is saving everything inside it and putting print_r it releases the properties. How to break this information down into indexes, something like:

echo $result['fields']['Codigo'];

The print_r($result) prints this:

Array
(
    [62] => Array
        (
            [Codigo] => 62
            [Cidade] => Porto Alegre
            [Bairro] => Espirito Santo
            [ValorVenda] => 105000
        )

    [69] => Array
        (
            [Codigo] => 69
            [Cidade] => Porto Alegre
            [Bairro] => Central
            [ValorVenda] => 90000
        ) ...
    
asked by anonymous 24.11.2015 / 21:33

1 answer

1

This question is very strange, since the answer is quite obvious. Now, you always need to specify an index for a particular record from which you want to get some information:

$registro = $results[62];
print $registro['ValorVenda'];

Even within a loop like foreach , the index for each record is implicitly considered:

foreach ($results as $result) {
    print $result['Bairro'] . PHP_EOL;
    print $result['ValorVenda']. PHP_EOL; 
    print "---" . PHP_EOL;
}
    
24.11.2015 / 22:11