Home > php教程 > php手册 > php-Arrays函数-array_combine-用两个数组的值作为新数组的键与值来新建一个数组

php-Arrays函数-array_combine-用两个数组的值作为新数组的键与值来新建一个数组

WBOY
Release: 2016-06-13 10:49:47
Original
1268 people have browsed it

array_combine() 函数   
      【功能】       通过合并两个数组来创建一个新数组,
          其中的一个数组是键名,另一个数组的值为键值。
      【使用范围】该函数为php5新增的一个函数。php5。
      【语法】       array array_combine( array keys,array values )
                           keys/必需/规定键名    values/必需/规定值
                           如果其中一个数组为空,或者两个数组的元素个数不同,则该函数返回 false。
      【示例】                
[php]
            $arr1 = array( "key1" => "value1", "key2" => "value2" ); 
            $arr2 = array( "key3" => "value3", "key4" => "value4" ); 
            $arr_combine = array_combine( $arr2, $arr1 ); 
            print_r( $arr_combine ); 
            /*Array
            (
                    [value3] => value1
                    [value4] => value2
            )*/ 

 

 

摘自 zuodefeng的笔记

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template