PHP Array combine() Function
Last Updated : 17 Mar 2025
The array_combine() function is an inbuilt function in PHP. This function is introduced in PHP 5. It is used to create an array by using one array for keys and another for its values.
Syntax
| Parameter | Description | Is compulsory |
|---|---|---|
| array_keys | The keys of the array to be used | compulsory |
| array_values | The values of the array to be used | compulsory |
Important note: Total number of elements in both of the arrays must be equal for the function to execute successfully otherwise, it will throw an error.
Example 1
Output:
Array ( [Php] => 95 [Core java] => 96 [C] => 80 [Javascript] => 75 [C++] => 68 )
Example 2
Output:
Array ( [Ajay] => 24 [Amit] => 30 [Rahul] => 35 )
Example 3
Output:
Array ( [a] => Cricket [b] => Football [c] => Badminton [d] => Hockey )
Example 4
Output:
Array ( [green] => guava [red] => cherry [yellow] => orange )
Next TopicPhp-array-compact-function