Show value associative arrangement

0

I have a stored procedure that returns the name of the provinces, passing the id of the country, province id. I get an array after making a call. print_r ($ a)

Array ( [0] => Array ( [id_loc] => 101 [descrip] => BA ) )

I want to get the value 'BA' to show in a form, I do a echo $a[$localidad]; but I get a vacuum or 'Array'

P.D: $localidad = '101';

What am I doing wrong? Thank you very much, best regards.

    
asked by GAL 14.02.2017 в 21:09
source

2 answers

0

It occurs to me that you can easily solve it with a function to which you pass the arrangement of localities ($ a) and the locality code (101) so that you return the description, something like this should be:

function nombrelocalidad($lista, $codigo)
{
    foreach ($lista as $localidad)
    {
        if ($localidad[id_loc] = $codigo)
        {
            return $localidad[descrip];
        }
    }
}

for example by calling the function with:

print_r(nombrelocalidad($a, 101));

should print you BA

Greetings.

    
answered by 14.02.2017 в 22:40
0

As a recommendation: if you want to filter the records, where the value of the "id_loc" field is equal to 101, this work can be done by the stored procedure, reducing the number of processes that your application server must perform. In terms of performance, this alternative is the correct one, since you are filtering by country ID, province ID and you could include the location ID.

If you do not have access to modify the stored procedure, to obtain the value you need, you must go through the array, comparing the value of the id_loc field with the value you are looking for (101), as indicated by M.Pacchiotti

    
answered by 14.02.2017 в 22:54