Alberto Luebbert
Alberto Luebbert

Reputation: 37

Read Array of Array in PHP

I'm trying to access a specific position in the array. My intention of this is to know position to position the following structure.

Array ( 
    [0] => Array ( 
    [id] => 215150311 
    [descripcion] => CHOCOLATE HERSHEYS 
    [status] => 23324 
    [precio] => 2.67 )

    [1] => Array ( 
    [id] => 215156968 
    [descripcion] => HUEVO DE CHOCOLATE 
    [status] => 7296 
    [precio1] => 9.72 
    ) )

I go around with a double forEach but I can not access a specific position such as Product Overview, field 2.

foreach($matriz as $row => $innerArray){
    foreach($innerArray as $innerRow => $value){
     //echo "el key es " .$innerRow . " y el valor es : " . $value. "<br/>";
     //echo "arreglo ".$matriz[$value[1]]; 
     echo "El valor es ".$value."<br/>";
     }
  }

What am I doing wrong?

Thanks for your support.

Upvotes: 1

Views: 48

Answers (1)

olibiaz
olibiaz

Reputation: 2593

Why do you use two foreach? It seems you need only one.

foreach($matriz as $row => $innerArray){
     echo "El valor es ".$innerArray['descripcion']."<br/>";
}

Upvotes: 3

Related Questions