/*123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789*///(按Alt可选多行,加内容……) //参数默认值function abc($a,$b,$c = 0){ echo $a,$b,$c;}abc(1,3); //可变参数function def(){ $arr = func_get_args(); var_dump($arr);}echo "<pre>";def(1,2,3,4,5,6);echo "</pre>"; //数组定义$arr1 = [];$arr2 = array();//索引数组$arr1 =[1,2,3,"abc"]; //关联数组$arr2 = [ "one" => 1, "two" => 2, "three" =>3 ];echo $arr2["one"]; //数组方法//推array_push($arr2,"xyz");//弹array_pop($arr2);//长度count($arr2);//判断数组中是否存在某个值in_array("1",$arr2);//数组合并$arr3 = array_merge($arr1,$arr2);//数组反转$arr4 = array_reverse($arr2);//数组去重$str5 = array_unique($arr1);//删除数组中的元素unset($arr1[0]);//重置reset($arr1); //echo "<pre>";//var_dump($arr2);//echo count($arr2);//var_dump(in_array("111",$arr2));//var_dump($arr5) //echo "</pre>"; //数组遍历//(先定义一波)$arr6 = [1,2,3,4,5,6,7];$arr7 = [ "one" => 1, "two" => 2, "three" => 3, "four" => 4];//1、for循环echo "<br>";for ($i = 0;$i <count($arr6);$i++){ var_dump($arr6[$i]);} //2、foreach 遍历foreach ($arr7 as $v){ var_dump($v);}foreach ($arr7 as $key=>$value){ echo $key; echo "______"; echo $value; echo "<br>";} //指针遍历echo "<pre>";var_dump(each($arr7));echo "</pre>";
时间: 2024-10-13 12:07:54