note 47526 deleted from ref.array by betz

From: Date: Fri, 19 Nov 2004 15:49:37 +0000
Subject: note 47526 deleted from ref.array by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80751@lists.php.net to get a copy of this message
Note Submitter: amsea at lvge dot com ---- array_merge()函数将两个或以上的数组合 并成一个新的数组,在合并数组元素的时候, 合并的顺序是按照原有数组被呼叫到的顺序来 决定。如果原有数组本身已经被重新排序过, 那么在数组合并完成以后,你必须针对产生出 来的新数组重新再排序一次。下面这个范例 就介绍这个函数的使用方式: <? /* 首先建立第一个数组 */ $fruitArray = array("apple", "orange", "banana", "Peach", "pear"); /* 接下来建立第二个数组 */ $vegArray = array("carrot", "green beans", "asparagus", "artichoke", "corn"); /* 现在使用array_merge()函数 将两个数组合并成一个新的数组 */ $goodfoodArray = array_merge($fruitArray, $vegArray); /* 最后我们把合并后的新数组的 所有元素的键(key)与值(value) 都显示在网页上 */ while (list($key,$value) = each($goodfoodArray)) { echo "$key : $value<br />"; } echo "<br><br> by http://oo8h.com/"; ?> 显示结果如下: 0 : apple 1 : orange 2 : banana 3 : Peach 4 : pear 5 : carrot 6 : green beans 7 : asparagus 8 : artichoke 9 : corn by http://www.psyc.cn/ ---- Reason: bad code

« previous php.notes (#80751) next »