How to stripslashes all the items of an array at once?

前端 未结 6 1370
面向向阳花
面向向阳花 2021-01-17 18:36

I need to stripslashes all items of an array at once.

Any idea how can I do this?

6条回答
  •  情书的邮戳
    2021-01-17 19:10

    foreach ($your_array as $key=>$value) {
    $your_array[$key] = stripslashes($value);
    }
    

    or for many levels array use this :

    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);
    
        return $value;
    }
    
    
    $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"));
    $array = stripslashes_deep($array);
    
    print_r($array);
    

提交回复
热议问题