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

WBOY
Release: 2016-05-31 19:30:21
Original
730 people have browsed it

本文以实例形式讲述了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));

Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template