Php multi-digit combination

Source: Internet
Author: User
The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods are actually

The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods are actually

The first choice is to explain that this article is somewhat suspected of a title party. I have previously written an article to compare the three methods for php to merge one-dimensional arrays, later, I used these three methods to process multi-dimensional arrays. The strange thing is that neither array_merge nor ++ reported an error. I thought they could also be used to process multi-dimensional arrays. After carefully observing the results, we found that the two methods were actually soy sauce.
Please refer to the code

    $array1 = array(2,4,"color" => "red");    $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);    $array3 = array("e","f","red"=>array("little"=>"little",3,5),2,4);    $array4 = array("a","b","red"=>array("little"=>"big",4,6),8,9);    echo "----------------array_merge---------------".PHP_EOL;    print_r(array_merge($array3,$array4));    echo "----------------+++++++++++++++++++++---------------".PHP_EOL;    print_r($array3+$array4);    echo "----------------array_merge_recursive---------------".PHP_EOL;    print_r(array_merge_recursive($array3,$array4));

The result is as follows:

----------------array_merge---------------Array(    [0] => e    [1] => f    [red] => Array        (            [little] => big            [0] => 4            [1] => 6        )    [2] => 2    [3] => 4    [4] => a    [5] => b    [6] => 8    [7] => 9)----------------+++++++++++++++++++++---------------Array(    [0] => e    [1] => f    [red] => Array        (            [little] => little            [0] => 3            [1] => 5        )    [2] => 2    [3] => 4)----------------array_merge_recursive---------------Array(    [0] => e    [1] => f    [red] => Array        (            [little] => Array                (                    [0] => little                    [1] => big                )            [0] => 3            [1] => 5            [2] => 4            [3] => 6        )    [2] => 2    [3] => 4    [4] => a    [5] => b    [6] => 8    [7] => 9)

After reading the code, I think you can see the meaning of soy sauce: array_merge and + treat the values of the First-dimensional array as a simple variable, then, the imported prime group is processed again by processing the one-dimensional prime group.
Only array_merge_recursive uses an iterative method to process the prime groups in each dimension.

Original article address: php multi-digit combination, thanks to the original author for sharing.

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.