Method of Realizing Array Recursive Escape in PHP

  • 2021-07-16 02:03:01
  • OfStack

This article describes the PHP implementation of array recursive escape method in the form of examples, and shares it with you for your reference. The specific methods are as follows:

The main function codes are as follows:


$arr = array('a"aa',array("c'd",array('e"f')));
function changes($arr){
 foreach($arr as $k=>$v){
 if (is_string($v)){
  $arr[$k] = addslashes($v);
 }else if (is_array($v)) { // If it is an array, escape it again .
  $arr[$k] = changes($v);
 }
 }
 return $arr;
}
print_r(changes($arr));

I hope this article is helpful to everyone's PHP programming.


Related articles: