Home >Backend Development >PHP Problem >How to escape php arrays
How to achieve escape of php array: first create a PHP sample file; then define an array; then implement recursive escape of the array through the custom changes method; finally print the conversion result through print_r.
Recommendation: "PHP Video Tutorial"
PHP method to implement array recursive escape
This article describes the method of implementing array recursive escape in PHP in the form of examples, and shares it with everyone 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)) { //若为数组,则再转义. $arr[$k] = changes($v); } } return $arr; } print_r(changes($arr));
The above is the detailed content of How to escape php arrays. For more information, please follow other related articles on the PHP Chinese website!