如何将2个参数传递给php中的array_map函数?

时间:2015-12-04 11:46:09

标签: php mysql web-deployment-project

$sql="select * from question_test where test_id='".$test_id."'   and  difficulty_level   BETWEEN  ".$_SESSION['difficulty_start']." and  ".$_SESSION['difficulty_end']." and question_id NOT IN ('".implode("', '", array_map('mysqli_real_escape_string', $_SESSION['question_attempt']))."')  order by rand()*favourability_level  desc";

运行上面的代码时出现错误:

  

警告:mysqli_real_escape_string()正好需要2个参数,1在第359行的C:\ xampp \ htdocs \ exam.php中给出

1 个答案:

答案 0 :(得分:1)

使用回调函数

XMLFileScanner

其中function array_map_callback($a) { global $con; return mysqli_real_escape_string($con, $a); } array_map('array_map_callback', $_SESSION['question_attempt']); 是连接变量。

所以你的$con变量将是:

$sql

或者您可以使用array_walk

$sql="select * from question_test where test_id='".$test_id."' and  difficulty_level BETWEEN  ".$_SESSION['difficulty_start']." and  ".$_SESSION['difficulty_end']." and question_id NOT IN ('".implode("', '", array_map('array_map_callback', $_SESSION['question_attempt']))."')  order by rand()*favourability_level  desc";