$where = '1=1';$keyword = $_GET['keyword']; if($keyword) { $where['title'] = array('like', "%$keyword%");}var_dump($where);竟然打印出来:A=1到底是怎么样的转换流程?
Reply content:
$where = '1=1';$keyword = $_GET['keyword']; if($keyword) { $where['title'] = array('like', "%$keyword%");}var_dump($where);竟然打印出来:A=1到底是怎么样的转换流程?
First of all, let me spit on the trough (not to vomit the groove will die!) ):
$where
is a string, what kind of a ghost are you writing $where['title']
?
You assign an array
assignment to a string in a string, what the hell is that?
I'll get rid of some of your problems assorted useless code, and then refine the problem:
$where = '1=1';$where['title'] = array();var_dump($where);
And above The spit groove corresponds to, we also step by step to see:
$where['title']
The expression is the $where
character of the subscript in the string, note that the subscript 'title'
's legal value is [0-string length minus 1], then PHP for the illegal subscript, in fact, and $where[0]
the role is consistent.
This problem is further simplified to:
$where = '1=1';$where[0] = array();var_dump($where);
Knowing that $where[0]
actually refers to the $where
first character of the string, the following is the " you array
assign an assignment to a string in a string, what's the ghost?" "
Let's do a test below:
var_dump( (string)array() );
What do you suppose will output?
PHP Notice: Array to string conversion in /home/nfer/temp.php on line 8string(5) "Array"
Well, it's a good idea to $where[0] = array();
assign a string Array
to $where
the first character of a string.
Bingo, the output isstring(3) "A=1"
Finally, let me also write a haunted code:
$where = 'A=1';$keyword = $_GET['keyword']; if($keyword) { $where['title'] = $keyword == 123;}var_dump($where);
What do you think the results will output?
1. $where = 1, this is right, first this is the string.
2. Then you put the $where as an array and put the $where[' title ' = Array (' Like ', "xxx"), assigning the value of the past, which is not scientifically put.