<span 1.创建数组
手动分配id健
</pre><pre code_snippet_id="347284" snippet_file_name="blog_20140515_1_2839562" name="code" class="php">//方法一
$nanms=array("just","you","tell me",);
//方法二
$names[0]="you";
$names[1]="tell me";
$names[2]="just";
2.添加值
$nanms=array("aa","bb");
$names[]="cc";
$names[]="dd";
echo $name{3].$name[2]."want".$name[0].$name[1];?>
//输出为“dd cc want aa bb
3.修改
$nanms=array("just","you","tell me","I");<pre code_snippet_id="347284" snippet_file_name="blog_20140515_3_2120405" name="code" class="php">echo $name{3].$name[2]."want".$name[1].$name[0];
//输出 I tell me want you just
$names[0]="you";
$names[1]="tell me";
$names[2]="just";
$names{3}="I";
echo $name{3].$name[2]."want".$name[0].$name[1];
//输出为“I just want you tell me
4.删除值
$nanms=array("just","tell me","I");
echo $name[2].$name[0]."want".$name[1];
//输出为:I just want tell me
unset($name[2]);
//输出为:just want tell me
$names[1]="tell me";
$names[2]="just";
$names{3}="I";
echo $name{3].$name[2]."want".$name[1];?>
输出为:“I just want tell me
5. 输出
$names[0]="you";
$names[1]="tell me";
$names[2]="just";
echo $name[2]."want".$name[0].$name[1];
输出为:just want you tell me
PHP 数组排序(sort)
数字索引数组排序:函数:sort(array, [sort type])
说明:sort()函数按升序对指定数组(第一个参数)进行排序。
sort函数第二参数作用为指定排序类型,是可选参数,可能的值为:
SORT_REGULAR: 默认值,不改变类型进行排序;
SORT_NUMERIC: 把值作为数字进行排序;
SORT_STRING: 把值作为字符串进行排序;
如数组中有4和”37″,按数字排序,4小于”37″;按字符串排序,4大于”37″;