php arrray combine 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);

Tags:

Php Example