How can I return data that is within arrays?

0

I'm using this code to pull features of a particular product:

<?php

$array = array(
    'key'       => '46dfg456465g4d654d65f4564dfg',
    'module'    => 'imoveis',
    'method'    => 'listar_origens' 
);

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

$res = $client->get($array);

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

?>

One of these features is the field which I need to retrieve 250 times because there are 250 different values for this field. The result of the script is this:

Array
(
    [0] => Array
        (
            [alias] => imo.DATA
            [field] => DATA
            [description] => Data cadastro
            [type] => Data
            [field_site] => 
        )

By putting $res[0]['field'] it returns me the first value that is DATA and so on as I change the values. I want to dynamically inside a loop retrieve the 250 values at once. I ask for help !!!

    
asked by anonymous 26.12.2014 / 14:27

2 answers

1

If you have an array that has an associative array inside each element, you can loop the first one and within the loop echo that key of the element of the first array that is being iterated.

Example:

echo "<pre>";
foreach($res as $item){
    echo $item['field'];
}
echo "</pre>";
    
26.12.2014 / 14:41
1

Just loop, for example:

Using FOR

for($i = 0; $i < count($res); $i++){
echo $res[$i]['field'];
}

Using FOREACH

foreach($res as $field){
echo $field['field'];
}

In both ways, it will result in the present value in $ res [0] ['field'], $ res [1] ['field'], $ res [2] ['field'] .. .

    
26.12.2014 / 14:41