The PHP array’s key statements are optional.
$array = ["foo", "bar"];
echo $array[0];
echo $array[1];
//Saídas
"foo"
"bar"
If keys are declared, access to their values shall be made through the specified key.
$foo = ["a" => "laranja", "b" => "maça"];
echo $foo["a"];
echo $foo["b"];
//Saídas
"laranja"
"maça"
But if there is a mixture of defined keys and other omitted keys, the index will be the first value of the array that does not have a key declared explicitly.
$foo = ["a" => "laranja", "b" => "maça", "morango", "c" => "pera", "banana"];
echo $foo["a"];
echo $foo["b"];
echo $foo[0];
echo $foo["c"];
echo $foo[1];
//Saídas
"laranja"
"maça"
"morango"
"pera"
"banana"
UPDATE
If you have an array within another array (multidimensional array), access to its values will depend on the association that has been defined.
$foo = [
"a" => "laranja",
"pera",
"vermelhas" => ["um" => "morango", "três" => "maçã", "framboesa"]
];
echo $foo[0];
echo $foo["vermelhas"];
echo $foo["vermelhas"]["dois"];
echo $foo["vermelhas"][0];
//Saídas
"pera"
Array to string
Undefined index: dois
"framboesa"
Yes! But I was in doubt now that I mentioned, if I have an array like this your $foo, and inside the key "a" I have another array, how would it look? I do not know if it is so understandable my question, but it would be basically if each key (equal to, b c) had an array inside as containing other values what would be the result and how would it access? If possible explain me in your question (if you can give an Edit)
– Devprogramacao
@Devprogramacao, updated my question :)
– Victor Carnaval