Good day. Do not kick hard, example:
$a = '1'; $a[$a] = '2'; echo $a; //12 Explain what is happening, why
$a = 'one'; $a[$a] = 'two'; echo $a // Warning: Illegal string offset Good day. Do not kick hard, example:
$a = '1'; $a[$a] = '2'; echo $a; //12 Explain what is happening, why
$a = 'one'; $a[$a] = 'two'; echo $a // Warning: Illegal string offset Because in the first case, $a interpreted as a string, the index '1' (the initial value of $a ) is interpreted as a number, and the record $a[$a] = '2' "is expanded" in "to write the second character (index 1) in string $a character '2' ". That is, '1' turns into '12' .
In the second case, 'two' cannot be interpreted as an index of a character in a string, and a message about this is displayed.
Source: https://ru.stackoverflow.com/questions/335390/
All Articles