Detailed explanation of array_combine() function in php

PHP中文网
Release: 2023-03-16 19:46:01
Original
1845 people have browsed it

There are many array functions, you can master them one by one slowly. Now let’s make an introduction to the array_combine function. Its function is to combine two arrays, one by array key name and the other by array value, into a new array.

Detailed explanation of the array_combine() function in php

Create a new array by merging two arrays, where one array element is the key name and the other array element For key values:

<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");
$c=array_combine($fname,$age);
print_r($c);
?>
Copy after login

Definition and usage

array_combine() function creates a new array by merging two arrays, where one array element is the key name and the other array element is key value.

Note: The number of elements in the key name array and the key value array must be the same!

Syntax

array_combine(keys,values);
Copy after login

Parameter Description

keys Required. Specifies the key name of the array. ​

values ​​Required. Specifies the key value of the array.

Technical details Return value:

Returns the merged array. If the two arrays have different numbers of elements, return FALSE.

PHP Version: 5+ Update log:

Before PHP 5.4, if the array is empty, an E_WARNING level error will be reported and FALSE will be returned.



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

Related labels:
source:php.cn
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