X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP array_combine() Function

PHP Array Reference PHP Array Reference

Example

Create an array by using the elements from one "keys" array and one "values" array:

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

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

Run example »

Definition and Usage

The array_combine() function creates an array by using the elements from one "keys" array and one "values" array.

Note: Both arrays must have equal number of elements!


Syntax

array_combine(keys,values);

Parameter Description
keys Required. Array of keys
values Required. Array of values

Technical Details

Return Value: Returns the combined array. FALSE if number of elements does not match
PHP Version: 5+
Changelog: Versions before PHP 5.4 issues E_WARNING and returns FALSE for empty arrays


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook