PHP, you may also fall into the trap of being asked today: $ var = 'test'; if (isset ($ var ['somekey']) {echo 'reachhere !!! ';} Will output 'reachhere !!! '? --- You may also fall into a trap when using PHP.
Asked today:
$ Var = 'test'; if (isset ($ var ['somekey']) {echo 'reach here !!! ';}
Will it output 'reach here !!! '? --- Of course not. I want to answer the question without thinking about it.
Sure enough, I fell into the trap! Will output! If you haven't fallen into the trap, congratulations, and you don't have to look down.
Now, let's analyze it. What is the value of isset? We print it out:
Var_dump ($ var ['somekey']); // => output: string (1) "t"
It is the character 'T', which is the first character of $ var. do you want to understand it here?
Because the variable $ var is a string, if you have learned the C language, you will know that it is a char array, so we can use $ var [0] $ var [1] $ var [$ I]... get the $ I + 1 character of $ var. So why did we get the first character of 'somekey? This is because php implements implicit type conversion here and converts the string here to the int type. If you have tried the intval ('somekey') function, you will know that the result is 0. Therefore, $ var ['somekey'] is eventually $ var [0. Finally, we get 'T '.
.