Home >Backend Development >PHP Tutorial >Examples of php array merging and recursive merging

Examples of php array merging and recursive merging

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:04:471156browse
  1. /**

  2. desc: array merge
  3. link: bbs.it-home.org
  4. date: 2013/2/22
  5. */
  6. $a = array( 'a' => 1, 'b' => 2 );
  7. $b = array( 'b' => 3, 'd' => 4 );

  8. //Array merge

  9. $array_merge = array_merge( $a, $b );
  10. echo '< ;pre>';
  11. print_r( $array_merge );

  12. //Array recursive merge

  13. $array_merge_recursive = array_merge_recursive( $a, $b );
  14. print_r( $array_merge_recursive );
  15. echo ' ';
  16. ?>

Copy the code

output result: Array ( [a] => 1 => 3 [d] => 4 ) Array ( [a] => 1 => Array ( [0] => 2 [1] => 3 )

[d] => 4 )

We can see: When array_merge encounters the same value, the second array key overwrites the first array key, while the array_merge_recursive function uses subscript merging for arrays of the same value.



Statement:
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