Home  >  Article  >  Backend Development  >  How to implement array recursive escaping in PHP, php array recursive escaping_PHP tutorial

How to implement array recursive escaping in PHP, php array recursive escaping_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:59969browse

How to implement array recursive escaping in PHP, php array recursive escaping

This article describes the method of implementing array recursive escaping in PHP in the form of examples, and shares it with everyone for your reference. The specific method is 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));

I hope this article will be helpful to everyone’s PHP programming design.

Problem with PHP recursively changing the value of a two-dimensional array

//Let’s have a check method first. You have to find a method, otherwise you can’t recurse public function check($result, $arr, $r) { $re=$r; foreach ($result as $value) { if ( $arr[$re]['name'] == $value['name'] || $arr[$re]['uid'] == $value['uid']) { $re = $re + 1; $this->check($result, $arr, $re); } } return $re; } //The following are the main methods public function xxxxxxxxxxxxxxxx() { $arr = array( array('id' => ; 1, 'name' => 'aaa', 'uid' => 1), array('id' => 2, 'name' => 'bbb', 'uid' => 2) , array('id' => 3, 'name' => 'ccc', 'uid' => 3), array('id' => 4, 'name' => 'ddd', 'uid' => 4), array('id' => 5, 'name' => 'ccc', 'uid' => 3), array('id' => 6, 'name ' => 'bbb', 'uid' => 2), array('id' => 7, 'name' => 'bbb', 'uid' => 2), array('id ' => 8, 'name' => 'fff', 'uid' => 6), array('id' => 9, 'name' => 'ccc', 'uid' => ; 3), array('id' => 10, 'name' => 'bbb', 'uid...The rest of the full text>>

PHP multi-dimensional array key name recursion

Try your blind writing skills
3e73993544408f6ed68598eb1e0ff2ef$ v)
$b[ intval($v['id']) ]=$v['unit_name'];
$a=$b;
print_r($a); //$a is the modified associative array

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871094.htmlTechArticleHow to implement array recursive escaping in PHP, php array recursive escaping This article describes how to implement array recursive escaping in PHP in the form of examples The escaping method is shared with everyone for your reference. The specific methods are as follows...
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