Correction status:qualified
Teacher's comments:加上自己的总结就更好了!
<meta charset="utf-8"> <?php //1.array_filter() 回调处理数组中的每个元素的值,仅返回结果为true的元素 $arr1 = [0,4,'',null,'0',false,'php']; echo '<pre>'; echo var_export($arr1,true).'<br>'; $arr2 = array_filter($arr1); echo var_export($arr2).'<br>'; $arr3 = ['html','css','javascript','asp','php']; $arr4 = array_filter($arr3,function($value){ return $value !== 'asp'; }); echo var_export($arr4).'<br>'; //2.array_walk() 对数组中每个元素的键和值进行处理 $arr5 = ['name'=>'admin','email'=>'admin@php.cn']; echo var_export($arr5).'<hr>'; array_walk($arr5,function(&$value,$keys){ echo $keys.':'.$value.'<br>'; }); echo '<br>'; array_walk($arr5,function($value,$key,$name){ if ($value != $name){ exit('无权查看'); }else{ exit($key.':'.$value); } },'admin');
点击 "运行实例" 按钮查看在线实例
<meta charset="utf-8"> <?php //1.array_filter() 回调处理数组中的每个元素的值,仅返回结果为true的元素 $arr1 = [0,4,'',null,'0',false,'php']; echo '<pre>'; echo var_export($arr1,true).'<br>'; $arr2 = array_filter($arr1); echo var_export($arr2).'<br>'; $arr3 = ['html','css','javascript','asp','php']; $arr4 = array_filter($arr3,function($value){ return $value !== 'asp'; }); echo var_export($arr4).'<br>'; //2.array_walk() 对数组中每个元素的键和值进行处理 $arr5 = ['name'=>'admin','email'=>'admin@php.cn']; echo var_export($arr5).'<hr>'; array_walk($arr5,function(&$value,$keys){ echo $keys.':'.$value.'<br>'; }); echo '<br>'; array_walk($arr5,function($value,$key,$name){ if ($value != $name){ exit('无权查看'); }else{ exit($key.':'.$value); } },'admin');
点击 "运行实例" 按钮查看在线实例