I've been given some code and one line is:
$key = $arr[($arr[$arr])];
I've never seen () in [] before, and Googling around I can't seem to find an explanation.
I don't know the value of $arr, but I wish to set it.
Doing:
$arr = 'blah';
$key = $arr[($arr[$arr])];
gives me Warning: Illegal string offset 'blah'
So I cannot print_r on it to find out what it looks like.
In general, there's nothing magical or strange here; the expression ($arr[$arr])
is equivalent to the expression $arr[$arr]
, just as (2)
is equivalent to 2
. At worst, the parens are redundant.
That being said, keys cannot have array-type, so trying to look up an element in an array using itself as a key is .... meaningless....