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

array_combine() function in PHP

WBOY
Release: 2023-08-31 16:46:01
forward
907 people have browsed it

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);
Copy after login

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);
?>
Copy after login

Output

The following is the output -

Array
(
[football] => david
[cricket] => steve
)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template