PHP Array function-array_combine ()

Source: Internet
Author: User

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

If one of the arrays is empty, or if the number of elements in the two array is different, the function returns
False

Array_combine (Array1,array2);

Array1: Required. Specified key Name

Array2: Required. Specified key value

Note: Two parameters must have the same number of elements

<?php
$a 1=Array(' A ', ' B ', ' C ', ' d ');
$a 2=Array(' Cat ', ' Dog ', ' Horse ', ' Cow ');
Print_r(Array_combine($a 1,$a 2));
?>

Output: Array ([a] = Cat [b] = Dog [c] = = Horse [d] = Cow)

<?php
$a 1=Array(' A ', ' B ', ' C ');
$a 2=Array(' Cat ', ' Dog ', ' Horse ', ' Cow ');
Print_r(Array_combine($a 1,$a 2));
?>

Output: Warning:array_combine () [Function.array-combine]: Both
Parameters should has an equal number of elements

PHP Array function-array_combine ()

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.