array combine php code example

Example 1: array_combine function in php

/* Array_combine is inbuilt function in php, which is use to combine two array in key value pair */
/* make sure both array should be of same length */

<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");

$c=array_combine($fname,$age);
print_r($c);
?>

/*
Output:
Array ( [Peter] => 35 [Ben] => 37 [Joe] => 43 )
*/
  
/*
I hope it will help you.
Namaste
Stay home stay safe
*/

Example 2: php combine arrays

$output = array_merge($array1, $array2);

Example 3: php array merge

array_merge ([ array $... ] ) : array

Example 4: associative array in php have same value join them

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

print_r($c);
?>

Example 5: php combine values of two arrays

$all_arrays = array_merge($array1, $array2, $array3, ...);