转义数组可以清除值

I have this loop that combines two arrays (questions and comments), i now want to escape it so i can use quotes and apostrophes in the comments fields.

$result = array();

    foreach ($questions as $key => $value){

        $value = mysqli_real_escape_string($value);

        if (array_key_exists($key, $comments)){

            $comments = mysqli_real_escape_string($comments);

            $result[$key] = "$value~ {$comments[$key]}";

        }else{

            @$result[$key] = "$value~ ";

             }

    }

For some reason mysqli_real_escape_string is knocking out the values (leaving only the delimiter (~)).

I have tried array_map / array_walk with array_keys outside the loop but it has the same effect:

$comments = array_map("mysqli_real_escape_string", array_keys($comments));

mysql_real_escape_string() for entire $_REQUEST array, or need to loop through it?

i want to check array's data with mysql_real_escape_string() function

How do you escape an entire array with mysqli_real_ecape_string? Any help would be greatly appreciated!

As the name suggests, mysqli_real_escape_string() operates on strings - you can't pass it an entire array at once. You need to loop through the array and escape each element individually.

Solved this with a simple while loop:

    $i = 0;
    while($i < 30){
    $result[$i] = mysqli_real_escape_string($link, $result[$i]);
    $i++;
    }