Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,003 questions

51,950 answers

573 users

How to merge two arrays in PHP

4 Answers

0 votes
$arr1 = array("php", "java", "c++", "python");
$arr2 = array("c#", "c", "javascript");
 
$merge_array = array_merge($arr1, $arr2);
 
print_r($merge_array);
 
 
 
 
 
/*
run:
 
Array
(
    [0] => php
    [1] => java
    [2] => c++
    [3] => python
    [4] => c#
    [5] => c
    [6] => javascript
)
 
*/


answered Apr 21, 2014 by avibootz
edited Apr 18, 2024 by avibootz
0 votes
$arr1 = array("php", "java", "c++", "python");
$arr2 = array("c#", "c", "javascript");
  
$merge_array = array_merge_recursive($arr1, $arr2);
  
print_r($merge_array);

  
  
  
/*
run:
  
Array
(
    [0] => php
    [1] => java
    [2] => c++
    [3] => python
    [4] => c#
    [5] => c
    [6] => javascript
)
  
*/

 



answered Jul 28, 2015 by avibootz
edited Apr 18, 2024 by avibootz
0 votes
$arr1 = array("php", "version", 8);
$arr2 = array("c", "version", 20);
  
$merge_array = array_merge_recursive($arr1, $arr2);
  
print_r($merge_array);

  
  
  
/*
run:
  
Array
(
    [0] => php
    [1] => version
    [2] => 8
    [3] => c
    [4] => version
    [5] => 20
)

*/

 



answered Jul 28, 2015 by avibootz
edited Apr 18, 2024 by avibootz
0 votes
$arr1 = array("aaa", "bbb", 1);
$arr2 = array("name" => "dan", "profession" => "programmer", 2);
  
$merge_array = array_merge_recursive($arr1, $arr2);
  
print_r($merge_array);

  
  
  
/*
run:
  
Array
(
    [0] => aaa
    [1] => bbb
    [2] => 1
    [name] => dan
    [profession] => programmer
    [3] => 2
)

*/

 



answered Feb 6, 2016 by avibootz
edited Apr 18, 2024 by avibootz
...