5
In some tests I did with PHP, I saw that it is possible to use keys ({}
) to access indexes of arrays
.
Example:
$array = ['a' => 1, 'b' => 2, 'c' => ['d' => 4]]
echo $array{'c'}{'d'}; // 4
echo $array{'c'}['d']; // 4
Until then, I thought only the brackets ([]
) did this.
So I want to ask:
Access an index of a
array
with keys instead of brackets has some special meaning?Why is it possible to use both forms?
Would using keys be considered out of the standard? I ask this because, although it works, I’ve never seen anyone using.
http://php.net/manual/en/language.types.array.php#example-61 See the note a little below the example.
– bfavaretto
http://answall.com/questions/77693/qual%C3%A9-a-utility-to-declare-Vari%C3%A1veis-atrav%C3%A9s-to-braces (I’m not saying it’s duplicate)
– Daniel Omine
@Danielomine may not be duplicated, but it’s very similar.
– Wallace Maxters