How to iterate array php

0

I have the following block that feeds an array

$insert = array();
for($i = 0; $i < 2; $i++){
   $insert[] = array(
                 "os"       => $cdOs,
                 "name"     => $iten->name
                 );
}

The array returns like this:

array (size=1)  0 =>     array (size=3)      'os' => string '84822' (length=5)      'name' => string 'Desert.jpg' (length=10)

I'm trying to recover the data like this:

foreach ( $values as $valor => $chave) {
  echo "Codigo da os insert: ".$chave->os." \n";   
}

But it shows nothing

    
asked by anonymous 14.11.2017 / 18:08

1 answer

4

You must use square brackets. When accessing an array position uses "[]", when accessing an object uses "->".

foreach ( $values as $valor => $chave) {
  echo "Codigo da os insert: " . $chave['os'] . " \n";   
}
    
14.11.2017 / 18:13