Correction status:qualified
Teacher's comments:
作业代码:
<?php //创建一个数组 $list = [1,2,3,2,5,2,66,32,33,66,2,3,6,2,3]; $arr=array(); $i =1; foreach (range("a","z") as $k){ $arr[$k] = $i; $i++; } //数组=>字符串转换 $str = implode($list,"|"); //string '1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26' //字符串转数组 $list = explode("|",$str); //数组=>变量 array_walk($arr,function ($v,$k){ echo "键为",$k," => ","值为",$v,"<br>"; }); list($a,$b,$c) = $list; echo $a,$b,$c; //变量=>数组 $list = compact('a','b','c'); //数组元素的回调处理,返回奇数 $res = array_filter($arr,function ($v){ return $v%2; }); var_dump($arr); for ($i=0;$i<=count($arr);$i++){ $i=$i?:1; $arr_key = array_search($i,$arr); echo $arr_key."=>".$arr[$arr_key]; } ?>
点击 "运行实例" 按钮查看在线实例