Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with big array

I'm trying to access some words from a string, using an array, here's the 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:

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

the output is:

Array
Array
Array

how can I make it so it shows:

barra
zona sul 
recreio

in the output, is it possible?

like image 538
André Cardoso Avatar asked Jul 29 '26 07:07

André Cardoso


2 Answers

 foreach($array_lugares[0] as $k => $lugar){
   echo $k;
   echo "</br>";
 }
like image 113
haknick Avatar answered Jul 31 '26 21:07

haknick


That is because you have a multidimensional array, you can loop through $lugar; also, 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 revisit the code you have and see if this is really the way you want to work with your data

like image 28
Ibu Avatar answered Jul 31 '26 21:07

Ibu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!