1.建立升序数组:range();
$numarr1 = range(1,4); //(1,2,3,4) $numarr2 = range(1,10,2); //(1,3,5,7,9) $letter = range(‘a‘,‘z‘); //(‘a‘,‘b‘,‘c‘......‘z‘)
2.使用循环访问数组:
$fruit[3] = (‘apple‘, ‘banana‘, ‘pear‘); for ($i = 0;$i<3;$i++) echo $fruit[$i].‘ ‘; //等价于下面代码 foreach ($fruit as $current) echo $current.‘ ‘;
3.使用不同索引数组:
$price = array(‘a‘ => 10, ‘b‘ => 20, ‘c‘ => 30); //等价于下面的代码: $price[‘a‘] = 10; $price[‘b‘] = 10; $price[‘b‘] = 10;
4.索引数组不能用for,但是可以用foreach(),list(),each()结构。
foreach ($price as $key => $value) echo $key.‘ => ‘.$value.‘ <br/>;
while (list($product, $pri) = each($price)) echo "$product - $pri<br>";
5.数组排序
sort() , asort() , ksort() , rsort() , usort() ;
重新排序:shuffle() ;
数组逆序:array_reverse() ;
6.explode()分割数组.
其他数组操作:each() , current() , reset() , end() , next() , pos() , prev().
7.对数组中每个元素应用任何函数:array_walk()
8.统计数组元素个数:count() , sizeof() , array_count_values()(频率表相关数组)
9.将数组转换成标量数组:extract()