PHPcode $ arrarray (); $ numhelloworld; if (isset ($ num) {$ arr $ num; var_dump ($ arr );} else {$ arr [] array (, 3); var_dump ($ arr);} after running, the browser displays a bit of confusion about arrays in string HTMLc.
PHP code
$arr = array();$num='hello world';if(isset($num)) { $arr = $num; var_dump($arr);} else { $arr[] = array(1,2,3); var_dump($arr);}
After running, the browser displays the string type
HTML code
string(11) "hello world"
But I have already set the arr as an array. I don't understand the internal cause, or $ arr = $ num; the variable arr has been declared again ???
------ Solution --------------------
This is the weak type ......
$ Str = "123 ";
Echo $ str [0]; // no problem in this way. output 1
------ Solution --------------------
Variable types can be automatically changed with context, which is a so-called weak type.
You have $ arr = $ num, so $ arr becomes a string.
------ Solution --------------------
The PHP type changes at any time and requires forced type conversion, like this: var_dump (array) $ arr );