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

WBOY
Release: 2016-07-13 10:19:59
Original
957 people have browsed it

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

Copy after login

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
$a=//original array;
$b=array();
foreach($a as $k=>$ 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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!