Home  >  Article  >  Backend Development  >  PHP array merging and splitting examples

PHP array merging and splitting examples

WBOY
WBOYOriginal
2016-07-25 08:54:07923browse
  1. $array1 = array("A","B","C","D");
  2. $array2 = array("1","2","3", "4");
  3. $array3 = array("!","@","#","$");
  4. $arrayX = array_merge($array1, $array2, $array3); //Merse 3 arrays Merge together
  5. print_r($arrayX);
  6. ?>
Copy the code

Example 2, merge php arrays.

  1. $array1 = array("AA"=>"A","BB"=>"B","CC"=>"C","DD"= >"D");
  2. $array2 = array("AA"=>"1","BB"=>"2","CC"=>"3","DD"=>" 4");
  3. $array3 = array("AA"=>"!","BB"=>"@","CC"=>"#","DD"=>"$") ;
  4. $arrayX = array_merge($array1, $array2, $array3); //Merge arrays
  5. print_r($arrayX);
  6. ?>
Copy code

Example 3, php array merge.

  1. //by bbs.it-home.org
  2. $array1 = array("AA"=>"A","BB"=>"B","CC" =>"C","DD"=>"D");
  3. $array2 = array("AA"=>"1","BB"=>"2","CC"=> "3","DD"=>"4");
  4. $array3 = array("AA"=>"!","BB"=>"@","CC"=>"#" ,"DD"=>"$");
  5. $arrayX = array_merge_recursive($array1, $array2, $array3);//Merge arrays
  6. print_r($arrayX);
  7. ?>
Copy code

Example 4, php array splitting.

  1. $array = array(1,2,3,4,5,6,7,8,9);
  2. $arrayX = array_splice($array, 2, 6); / /Get the 2nd element to the 7th element of the array
  3. print_r($array);
  4. print_r($arrayX);
  5. ?>
Copy code

>>>> Articles you may be interested in: PHP array splitting and array joining php chunk function split array instance php mb_chunk_split function supports wide character split Example of php space-separated text into array A simple example of splitting a Chinese string into an array in php Several ways to split Chinese and English strings in php php split() string splitting function application example Solution to php splitting GBK Chinese garbled characters Example of php string splitting function explode php array merge sample code Two ways to merge two arrays in PHP php method to merge arrays according to classification php array operation example: merging arrays PHP array merging, appending and connecting methods (array_merge(), array_combine() functions) Examples of php array merging and recursive merging PHP array merging example learning



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