PHP implementation of array recursive escape method, PHP array recursive escape
In this paper, we describe the method of implementing the recursive escape of array in PHP, and share it for your reference. Here's how:
The main function code is 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)) {//If an array, then escaped. $arr [$k] = changes ($V); }} return $arr;} Print_r (Changes ($arr));
I hope this article is helpful to everyone's PHP programming.
The problem of PHP recursively changing the value of two-dimensional array
First, a check method, you have to make a method, or you can not recursive 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 is the main method public function xxxxxxxxxxxxxxxx () {$arr = array (' id ' = = 1, ' name ' = ' aaa ', ' uid ' = 1), Arra Y (' id ' = = 2, ' name ' = ' bbb ', ' uid ' = + 2), array (' id ' = + 3, ' name ' = ' CCC ', ' uid ' = = 3), array (' ID ' =&G T 4, ' name ' = ' ddd ', ' uid ' and ' = 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 ' = ' + ', ' name ' = ' bbb ', ' uid '). ..... Remaining full text >>
Recursive key names for PHP multidimensional arrays
Try Blind writing ability
$a =//original array;
$b =array ();
foreach ($a as $k = $v)
$b [Intval ($v [' id '])]= $v [' Unit_name '];
$a = $b;
Print_r ($a); $a as the modified associative array
http://www.bkjia.com/PHPjc/871094.html www.bkjia.com true http://www.bkjia.com/PHPjc/871094.html techarticle PHP implements the recursive escape method of the array, the PHP array recursive escape this article in the form of an example of the PHP implementation of the recursive array of the method of escaping, shared for everyone for reference. Specific methods such as ...