The Array_combine () function in PHP is detailed

Source: Internet
Author: User
There are a lot of array functions that can be mastered slowly one at a time. Now let's do an introduction to the Array_combine function. Its function is to put two arrays one by the array key name, one by the array value group to synthesize the new array.

The Array_combine () function in PHP is detailed

A new array is created by merging two arrays, one of which is the key name and the other array element is the key value:

<?php$fname=array ("Peter", "Ben", "Joe"), $age =array ("n", "PNs", "a"), $c =array_combine ($fname, $age);p Rint_r ($c) ;? >

Definition and usage

The Array_combine () function creates a new array by merging two arrays, one of which is the key name and the other element is the key value.

Note: Key an array groups and key-value arrays must have the same number of elements!

Grammar

Array_combine (keys,values);

Parameter description

Keys required. Specifies the key name of the array.

values are required. Specifies the key value of the array.

Technical details return value:

Returns the merged array. Returns FALSE if the number of elements in the two array is different.

PHP version: 5+ update log:

Before PHP 5.4, if the array is empty, the e_warning level error is reported and FALSE is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.