PHP array_combine() Function

Definition and Usage

The array_combine() function creates an array by using the elements from one "keys" array and one "values" array.
Note: Both arrays must have equal number of elements!

Syntax

array_combine(keys,values);

 


Example

Create an array by using the elements from one "keys" array and one "values" array:
<?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 )