Home  >  Article  >  Backend Development  >  How to escape php arrays

How to escape php arrays

藏色散人
藏色散人Original
2020-10-09 10:39:461776browse

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.

How to escape php arrays

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn