PHP implementation of array recursive escape method, PHP array recursive escape _php tutorial

Source: Internet
Author: User
Tags php programming

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.