PHP : array_combine() function
Description
The array_combine() function is used to creates an array by using one array for keys and another for its values.
Version
(PHP 4 and above)
Syntax
array_combine(array_keys, array_values)
Parameter
| Name | Description | Required / Optional |
Type |
|---|---|---|---|
| array_keys | The keys of the array to be used. | Required | Array |
| array_values | The values of the array to be used. | Required | Array |
Return value
The combined array, FALSE if the arrays are empty or the number of elements for each array isn't equal.
Value Type : Array
Pictorial Presentation :

Example :
<?php
$subject =array('Language', 'Math', 'Science', 'Geography');
$marks = array(77, 80, 90, 75);
$subject_marks=array_combine($subject, $marks);
print_r($subject_marks)
?>
Output
Array ( [Language] => 77 [Math] => 80 [Science] => 90 [Geography] => 75 )
View the example in the browser
See also

