Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_combine()

Example

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);
?>

Definition and Usage

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.

Syntax

array_combine(keys, values)

Parameter Values

Parameter

Description

keys

Required. An array of keys

values

Required. An array of values

Technical Details

Return Value:

Returns the combined array, or FALSE if the number of elements does not match.

PHP Version:

5+

Changelog:

Versions prior to PHP 5.4 issue an E_WARNING and return FALSE for empty arrays.