PHP Array Function : combine()

The array_combine() function is used to create an arry by using the elements of first array as key and the element of another array as values. Both arrays must have equal number of elements. The basic syntax is as follows :
 array_combine(keys, values);
Where keys refers to array name for key and values refers to array name for values.

Example :
<?php

  $name = array("John snow", "Luci Hunt", "James Bond", "Bruce wayne");
  $age = array(35, 40, 61, 48);

  $new_arr = array_combine($name, $age);

  foreach($new_arr as $key => $value) {
    echo $key . " : " . $value . "<br/>";
  }
?>
Output :

John snow : 35
Luci Hunt : 40
James Bond : 61
Bruce wayne : 48


Next Topic :