Home  >  Article  >  Backend Development  >  PHP实现数组递归转义的方法_PHP

PHP实现数组递归转义的方法_PHP

WBOY
WBOYOriginal
2016-05-31 19:30:21734browse

本文以实例形式讲述了PHP实现数组递归转义的方法,分享给大家供大家参考之用。具体方法如下:

主要功能代码如下:

$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));

希望本文所述对大家的PHP程序设计有所帮助。

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