$ArrayList = ArrayListay(); Array_push($ArrayList, el1, el2 ... eln);
但其实有一种更直接方便的做法,代码如下:
$ArrayList = ArrayListay(); $ArrayList[] = el1; $ArrayList[] = el2; ... $ArrayList[] = eln;
添加一个或多个元素,代码如下:
<?php $ArrayList1 = ArrayListay("a", "b"); Array_push($ArrayList1, "c", "d"); print_r($ArrayList1); ?>
ArrayListay ( [0] => a [1] => b [2] => c [3] => d )
在数组开头插入元素
1. ArrayListay_unshift,使用方法,代码如下:
<?php $array_Qlist = ArrayListay("军民联防", "banana"); Array_unshift($array_Qlist, "西瓜", "脚本之家"); print_r($array_Qlist); ?>
ArrayListay ( [0] => 西瓜 [1] => 脚本之家 [2] => 军民联防 [3] => banana )
<?php $array_Qlist = ArrayListay('a', 'B'); $array_Qlist = Array_merge(ArrayListay('front' => '你好www.jb51.net'), $array_Qlist); /* ArrayListay ( [front] => 你好www.jb51.net [0] => a [1] => b ) */ ?>
<?php $array_Qlist = Array('a', 'B'); $array_Qlist = Array('front' => '你好小www.jb51.net') + $array_Qlist; ?>
3. 在元素结尾添加关联数组元素,代码如下:
<?php $array_Qlist = ArrayListay('a', 'B'); $array_Qlist['front'] = '你好www.jb51.net'; /* 输出 ArrayListay ( [0] => a [1] => b [front] => 你好www.jb51.net ) */ ?>
希望本文所述对大家的PHP程序设计有所帮助。