Help understand how brackets are used ... Rookie Question

I understand what the next line does, but I don't understand how brackets are used? I always used brackets in if, while and other statements, but I never used them that way.

Are there rules for using them this way? Shouldn't they be used that way? Any help would be appreciated ... Thanks

${$key} = $temp;
+3
source share
3 answers

In this particular case, there is no difference between using parentheses and not.

So your code is equivalent to the following:

$$key = $temp;

Brackets are commonly used to force PHP to interpolate variables in strings, which is not necessary in this case.

:

${$array[0]} = $temp;

$$array[0] = $temp;

, ($$array)[0], $($array[0])

+3
+1

Variables seem to be used .

Otherwise, such brackets are usually used for an interpolation variable in strings, where the variable is a property of an object or an element of an array.

In the above example, they are not needed. It also seems that you can index an array with variable variables without any problems .

0
source

Source: https://habr.com/ru/post/1788103/


All Articles