Easy way to apply a function to an array

前端 未结 7 789
無奈伤痛
無奈伤痛 2020-12-03 14:31

I am aware of array_walk() and array_map(). However when using the former like so (on an old project) it failed

array_walk($_POST,          


        
7条回答
  •  隐瞒了意图╮
    2020-12-03 14:37

    mysql_real_escape_string() won't work unless you've made a mysql connection first. The reason it is so cool is that it will escape characters in a way to fit the table type. The second [optional] argument is a reference to the mysql connection.

    $_POST is always set up as key->value. So, you array_walk calls mysql_real_escape_string(value, key). Notice the second argument is not a reference.

    That is why it does not work. There are several solution already mentioned above.

提交回复
热议问题