Latest web development tutorials

PHP array_combine () function

PHP Array Reference Complete PHP Array Reference

Examples

To create a new array by combining two arrays, one array element for the key name, another array element is key:

<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");

$c=array_combine($fname,$age);
print_r($c);
?>

Running instance »

Definition and Usage

array_combine () function by combining two arrays to create a new array, one array element for the keys, the key element is another array.

Note: The number of elements in the array keys and values of the array must be the same!


grammar

array_combine( keys , values );

参数 描述
keys 必需。规定数组的键名。
values 必需。规定数组的键值。

technical details

return value: Returns an array combined. If the number of elements in the two arrays are not the same, it returns FALSE.
PHP version: 5+
Update log: Before PHP 5.4 version, if the array is empty, it will be reported E_WARNING level error and return FALSE.


PHP Array Reference Complete PHP Array Reference