Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_combine() Function

PHP array_combine() Function

PHP Array Reference ManualComplete PHP Array Reference Manual

Example

Create a new array by combining two arrays, where elements of one array become the keys and elements of the other become the values:

Run Example »


Definition and Usage

The array_combine() function creates a new array by combining two arrays, where elements of one array become the keys and elements of the other become the values.

**Note:** The key array and the value array must have the same number of elements!


Syntax

array_combine(

keys

,

values

);

Parameters Description
keys Required. Specifies the keys of the array.
values Required. Specifies the values of the array.

Technical Details

Return Value: Returns the combined array. If the two arrays have a different number of elements, returns FALSE.
PHP Version: 5+
Changelog: Before PHP 5.4, an empty array would trigger an E_WARNING level error and return FALSE.

PHP Array Reference ManualComplete PHP Array Reference Manual