$a = '86';
var_dump($a); //ouput string(2) "86"
var_dump($a['wtf']); //output string(1) "8"
The second oputput is strange although that is equivalent to
var_dump($a[0]); ////output string(1) "8"
Can somebody explain me why var_dump($a[‘wtf’]); output string(1) “8” ?
$a is a string.
A string in php can be regarded as an array of chars (so $a[0] == ‘8’ and $a[1] == ‘6’)
Now, you tried to access the string at place [‘wtf’], since PHP expects a number there, it will try to convert ‘wtf’ to number. Since there is no digit in this string, it is regarded as 0.
‘wtf1’ is converted to 0 as it checks the first characters (thanks to sad bube)
‘1wtf’ is converted to 1
‘100’ is converted to 100
‘dfsdgrgergregr’ is converted to 0