Home >Backend Development >PHP Tutorial >php数组,批改,遍历,函数等
php数组,修改,遍历,函数等
php W3c http://www.w3school.com.cn/php/func_array_search.asp
php数组的形式:
①,数值数组
形如:array(v1,v2,v3,v4,.....)
array(值1,值2,值3, ……)
②,关联数组
形如:array(k1=>v1,k2=>v2,k3=>v3,.......)
array(键1=>值1,键2=>值2,键3=>值3,……)
③,多维数据
$arr_arr = array(array(4567,77.7,99,100),"aa","bb",cc);
数据的显示:
print_r()
var_dump()(包含了类型,长度等信息)
$arr = array(1,2,3,4,5);
print_r($arr);
echo "
";
var_dump($arr);
结果是:
Array( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5)
array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5)}
数组的遍历foreach():
$arr = array(1,2,3,4,5);
foreach($arr as $k => $v){
echo "key => value is ".$k."=>".$v."
";
}
多维数组的输出:
$arr_arr = array(array(4567,77.7,99,100),"aa","bb",cc);
echo "var_dump 多维数组
";
var_dump($arr_arr);
echo "print_r() 多维数组
";
print_r($arr_arr);
显示:
var_dump 多维数组
array(4) { [0]=> array(4) { [0]=> int(4567) [1]=> float(77.7) [2]=> int(99) [3]=> int(100) } [1]=> string(2) "aa" [2]=> string(2) "bb" [3]=> string(2) "cc"}print_r() 多维数组
Array( [0] => Array ( [0] => 4567 [1] => 77.7 [2] => 99 [3] => 100 ) [1] => aa [2] => bb [3] => cc)
数组函数:
删除函数:unset($arr['k']);
值排序:sort(),rsort()(倒序)
键排序:ksort(),krsort()
求和:array_sum($array)
个数:count()sizeof()
查找:in_array(value,$array)
array_search(value,$array)
哎先看看W3Cschool上的,贴个目录,学习计划搞起来,熟悉一下吧:
一,php基础篇
五,php与ajax
六,php参考手册