Value of one of the array fields

2

I need to check the value of one of the fields in an array but I can not.

var_dump($array_exemplo);

array(1) {
   [0]=>
   array(3) {
     ["primeiro"]=>
        string(1) "1"
     ["segundo"]=>
        string(1) "2"
     ["terceiro"]=>
        string(1) "3"
   }
}

var_dump($array_exemplo["segundo"]);
  

Notice: Undefined index: second in ...

    
asked by anonymous 15.11.2017 / 14:20

1 answer

3

You have an array inside another so you can not pretend you do not have this array .

$array_exemplo = array(
    0 => array(
        "primeiro" => "1",
        "segundo" => "2",
        "terceiro" => "3"
    )
);
var_dump($array_exemplo);
var_dump($array_exemplo[0]);
var_dump($array_exemplo[0]["segundo"]);

See running on ideone . And no Coding Ground . Also put it in GitHub for future reference .

    
15.11.2017 / 15:07