PHP implements array recursive escape. php array recursive escape _ PHP Tutorial

Source: Internet
Author: User
PHP implements array recursive escape, and php array recursive escape. PHP implements array recursive escape. This article describes how php implements array recursive escape in the form of an example. For example, PHP implements array recursive escape and php array recursive escape.

This article describes how to implement recursive escape of arrays in PHP in the form of examples and shares it with you for your reference. The specific method is as follows:

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) {// escape if it is an array. $ arr [$ k] = changes ($ v) ;}return $ arr;} print_r (changes ($ arr ));

I hope this article will help you with PHP programming.


PHP recursively changing the values of two-dimensional arrays

// Check the method first. Otherwise, the 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 main method is public function xxxxxxxxxxxxxxxx () {$ arr = 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 ...... remaining full text>

Recursive key name of php multi-dimensional array

Try the blind write capability
$ 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 joined array

In this article, examples are provided to illustrate how PHP implements recursive escape of arrays. The specific method is as follows...

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.