Arrays

How to combine 2 arrays?

Questions by kirupa lakshmi

Showing Answers 1 - 18 of 18 Answers

ramadeviv

  • Jan 12th, 2010
 

array_combineCreates an array by using one array for keys and another for its values

<?php
$a 
= array('green''red''yellow');
$b = array('avocado''apple''banana');
$c array_combine($a$b);

print_r($c);
?>

  Was this answer useful?  Yes

Manoj24

  • Jan 14th, 2010
 

<?php
$a1=array("a"=>"Horse","b"=>"monkey");
$a2=array("c"=>"Cow","b"=>"Cat");
print_r(array_merge($a1,$a2));
?>

  Was this answer useful?  Yes

gmanon

  • Feb 2nd, 2010
 

//The array_merge() and array_combine(), both combine arrays. 

/*It merges two arrays, one after the other.*/

$comArrays = array_merge(Array1,Array2);
$comArrays = $larger_array12;

/*It combines two arrays where one pass to be the index or key
value and the other the array value.*/

$combArrays = array_combine(Array1,Array2);
$combArrays = $same_size_array[Array1] = Array2);

  Was this answer useful?  Yes

Arrays can be combined using array_merge() function

Description of array_merge function is as follows.
array_merge() merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions