Help with a large array

I am new to php and I am trying to filter out some words from a string using an array, here is an array:

$array_lugares = array
(
array("barra"=>array
(
/*SENTIDO BARRA*/
"Sao conrado"=>array("-22.999743","-43.270694"),
"Elevado do Joa"=>array("-22.999429","-43.27317")
),
"zona sul"=>array
(
/*SENTIDO ZONA SUL:*/
"passarela da barra"=>array("-23.008346","-43.303708"),
"barra grill"=>array("-23,010576", "-43,302028"),
"lagoa barra"=>array("-22,997348", "-43,263200")
),
"recreio"=>array
(
/*SENTIDO RECREIO:*/
"passarela da barra"=>array("-23.008283","-43.303634"),
"rio mar"=>array("22.999958","-43.402648"),
"ribalta"=>array("-22,999753", "-43,409211")
)));

when i do this:

foreach($array_lugares[0]['zona sul'] as $lugar){
echo $lugar;
echo "</br>";
}

conclusion:

Array
Array
Array

how can i do this so that it shows:

barra
zona sul 
recreio

output, is this possible?

+3
source share
3 answers
 foreach($array_lugares[0] as $k => $lugar){
   echo $k;
   echo "</br>";
 }
+3
source

This is because you have a multidimensional array, you can also scroll $lugar;, and it will give you the correct output

Update:

foreach($array_lugares[0]['zona sul'] as $lugar){
   foreach ($lugar as $value) {
     // further inside the array

   }

 echo "</br>"; 

} 

but I think you should review the code that you have and see if this is really the way you want to work with your data.

+1
source

because it $array_logares[0]['zona sul']provides you with an object

array
(
/*SENTIDO ZONA SUL:*/
"passarela da barra"=>array("-23.008346","-43.303708"),
"barra grill"=>array("-23,010576", "-43,302028"),
"lagoa barra"=>array("-22,997348", "-43,263200")
)

and each element is an array of (points). If you need names (instead of an array of points), you will do the following:

foreach(array_keys($array_logares[0]['zona sul']) as $lugar)

if you want a name and period, you should do this:

foreach($array_lugares[0] as $name => $lugar)
0
source

All Articles