Combine elements from one “keys” array with another “values” array to create a new array.
<?php $fname=array(“Peter”,“Ben”,“Joe”); $age=array(“35”,“37”,“43”); $c=array_combine($fname,$age); print_r($c); ?> |
The array_combine()
function generates an array using elements from one “keys” array and another “values” array.
Note: Both arrays must have the same number of elements.
array_combine(keys, values) |
Parameter |
Description |
keys |
Required. An array of keys |
values |
Required. An array of values |
Return Value: |
Returns the combined array, or |
PHP Version: |
5+ |
Changelog: |
Versions prior to PHP 5.4 issue an |