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

前端 未结 6 1316
面向向阳花
面向向阳花 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:36

    For uni-dimensional arrays, array_map will do:

    $a = array_map('stripslashes', $a);
    

    For multi-dimensional arrays you can do something like:

    $a = json_decode(stripslashes(json_encode($a)), true);
    

    This last one can be used to fix magic_quotes, see this comment.

提交回复
热议问题