Tác dụng của hàm array_combine()
The array_combine()
function creates an array by using one array for keys and another for its values.
The following table summarizes the technical details of this function.
Return Value: | Returns the combined array, FALSE if the number of elements for each array isn't equal. |
---|---|
Changelog: | Versions before PHP 5.4.0 issues E_WARNING and returns FALSE for empty arrays. |
Version: | PHP 5+ |
Syntax
The basic syntax of the array_combine()
function is given with:
The following example shows the array_combine()
function in action.
Example
Run this code »
Parameters
The array_combine()
function accepts the following parameters.
Parameter | Description |
---|---|
keys | Required. Specifies the array of keys to be used. |
values | Required. Specifies the array of values to be used. |
Note: Both the arrays you want to combine using the array_combine()
function must have equal number of elements, otherwise it returns FALSE
.
More Examples
Here're some more examples showing how array_combine()
function basically works:
If the array you want to use for keys has duplicate values, the later value will prevail as key in the combined array, as shown in the following example:
Example
Run this code »