Home  >  Article  >  Backend Development  >  php数组函数序列之array_combine() - 数组合并函数使用说明_php技巧

php数组函数序列之array_combine() - 数组合并函数使用说明_php技巧

WBOY
WBOYOriginal
2016-05-17 09:14:57987browse
array_combine() 定义和用法
array_combine() 函数通过合并两个数组来创建一个新数组,其中的一个数组是键名,另一个数组的值为键值。

如果其中一个数组为空,或者两个数组的元素个数不同,则该函数返回 false。

语法
array_combine(array1,array2)
参数 描述
array1 必需。规定键名。
array2 必需。规定值。

提示和注释
注释:两个参数必须有相同数目的元素。

例子
复制代码 代码如下:

$a1=array("a","b","c","d");
$a2=array("Cat","Dog","Horse","Cow");
print_r(array_combine($a1,$a2));
?>

输出:

Array ( [a] => Cat [b] => Dog [c] => Horse [d] => Cow )
Statement:
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