Value of one of the array fields

Asked

Viewed 39 times

2

I need to check the value of one of the fields of a array but I’m not getting it.

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: segundo in ...

1 answer

3


You have a array inside of another then can not pretend that does not have this array middleman.

$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"]);

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • Perfect... that’s what it was.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.