array_merge() 函数的用法
array_merge() 函数把两个或多个数组合并为一个数组。
例一:
<?php $fruitArray = array("apple", "orange", "banana", "Peach", "pear"); $vegArray = array("carrot", "green beans", "asparagus", "artichoke", "corn"); $goodfoodArray = array_merge($fruitArray, $vegArray); print_r($goodfoodArray); ?>
输出的结果是:
Array ( [0] => apple [1] => orange [2] => banana [3] => Peach [4] => pear [5] => carrot [6] => green beans [7] => asparagus [8] => artichoke [9] => corn )
例二:
<?php $fruitArray = array("apple", "orange", "banana", "Peach", "pear"); $vegArray = array("carrot", "green beans", "apple","asparagus", "artichoke", "corn"); $goodfoodArray = array_merge($fruitArray, $vegArray); print_r($goodfoodArray); ?>
输出的结果是:
Array ( [0] => apple [1] => orange [2] => banana [3] => Peach [4] => pear [5] => carrot [6] => green beans [7] => apple [8] => asparagus [9] => artichoke [10] => corn )
对比可以看到:键名是整数,如果其值相同,并不会覆盖原有的。数组的键名以 0 开始进行重新索引 。
千里之行,始于足下。改变现在,就是改变未来。改变未来,从现在开始。
个人网站:http://www.wangkongming.cn