Home  >  Article  >  Backend Development  >  array_combine() function in PHP

array_combine() function in PHP

WBOY
WBOYforward
2023-08-31 16:45:06854browse

array_combine() function in PHP

array_combine() function creates an array by using one array as keys and another array as values. It returns the combined array. If the number of elements in each array does not match, the function returns FALSE.

Syntax

array_combine(keys, values);

Parameters

  • keys − Array of keys.

  • values ​​− Array of values.

Return value

array_combine() function returns the combined array. Returns FALSE if the number of elements in each array does not match.

The following is an example of merging two arrays.

Example

Demonstration

<?php
$sports= array(&#39;football&#39;, &#39;cricket&#39;);
$players= array(&#39;david&#39;, &#39;steve&#39;);
$res = array_combine($sports, $players);
print_r($res);
?>

Output

The following is the output -

Array
(
[football] => david
[cricket] => steve
)

The above is the detailed content of array_combine() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete