Home > Article > Backend Development > How to implement array recursive escaping in PHP, php array recursive escaping_PHP tutorial
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.
//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>>
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