How to record variables from this array?

Asked

Viewed 126 times

1

I’m developing a system that uses a web-service to recover the data needed to feed you, in the real estate segment. I am learning PHP and have many problems learning arrays. You could show me how I could recover specific data from this array: http://axitech.com.br/vista ...

Man print_r is returning all records consulted, would like to be able to save CATEGORIA BAIRRO VALOR within 3 different variables to be able to use them later. I imagine in this case we have a two-dimensional array, that’s it?

Evolution:

echo '<pre>'; print_r($res[523]['Data cadastro']); echo '</pre>';

With this code I can return a specific data from a specific record. But what if I wanted to return a specific data of all the elements? I tried the first empty Intel thinking that it would return me to Date registration of all records UNSUCCESSFUL:

echo '<pre>'; print_r($res[]['Data cadastro']); echo '</pre>';

This is the complete code of my script:

<?php

$array = array(
        'key' => '',
        'module' =>'imoveis',
        'method' => 'busca_imoveis',
        'field' => array(
            'DATA'          => 'Data cadastro',
            'CODIGO'        => 'Codigo',
            'CATEGORIA'     => 'Categoria',
            'UF'            => 'UF',
            'CIDADE'        => 'Cidade',
            'BAIRRO'        => 'Bairro',
            'ENDERECO'      => 'Endereco',
            'NUMERO'        => 'Numero',
            'VLR_VENDA'     => 'Valor',
            'DORMITORIO'    => 'Dormitorios',
            'URL_FOTO'      => 'Url',
            'IMAGEM_G'      => 'Foto'
     ),
        'filter' => array(
            'CONDICAO' => 'VLR_VENDA > 0'
    )
);

$client = new SoapClient(null, array(
        'uri'       => 'http://soap.imo.bi/',
        'location'  => 'http://soap.imo.bi/soap.dll',
        'trace'     => 'trace'
));

$array['order'] = array('VLR_VENDA' => 'DESC');
//$array['limit'] = '0, 10';
$res = $client->get($array);

echo '<pre>';
    print_r($res);
echo '</pre>';

?>
  • 1

    In case you need to ask these 3 fields of a single item or all of the array? ja tried one foreach?

  • That one print_r($res) is returned to me all the items from array with all its characteristics as shown in the link http://axitech.com.br/vista/index.php. I want to break this up array to be able to do whatever you want with this data.

1 answer

3


To take an item from a multidimensional array, just use more than one index.

Examples:

$teste1 = $array[0]['subitem']; 
$teste2 = $array['item']['subitem'];

Note correct use of upper and lower case when key => value.

EDIT: As the question is updated:

 for ($i = 0; $i < count( $res ); ++$i ) {
    print $res[$i]['Data cadastro'];
 }
  • You gave me a great help and showed me the main requisitions of this system that I will develop. Thank you very much. If I could give you 500 points. rsrs

  • 1

    @Marcosviniciusnasc.Pereira does not need to exaggerate, the "Accept" you gave there next is more than enough, :) - But I recommend you do more tests with the basics of the language to get her way more easily.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.