Blogger Information
Blog 12
fans 0
comment 0
visits 10487
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组元素的回调处理8月27日19:55
A骆长林的博客
Original
557 people have browsed it

实例

<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');

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:加上自己的总结就更好了!
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments