Blogger Information
Blog 14
fans 0
comment 0
visits 7852
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
变量之间的转换+回调+for()循环---2018-08-25 22:21:38
Taoing的博客
Original
566 people have browsed it

回调实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

</body>
</html>
<?php
/**
 * 数组的回调
 * 参数有参数
 */
//1.array_filter($arr,$callback)
//2.array_walk($arr,$callback())
//1.array_filter():回调处理数组中的每个元素,仅返回结果为true的元素
$ct = [1,2,0,'','',null,false,88,false,'php',null];
echo '原数组',var_export($ct,true),'共有:',count($ct),'个元素<hr>';

$ct1 = array_filter($ct);
echo '新数组',var_export($ct1,true),'共有:',count($ct1),'个元素<hr>';
//传入一个回调:匿名函数
$hs =['php','js','h5','java','python'];
$hs1 = array_filter($hs, function ($sc){
    return $sc !== 'python';

});
echo var_export($hs1),'<hr>';
//2.array_walk():对数组每个元素的键和值进行处理
$arr =['name'=>'root','password=>admin'];
echo var_export($arr,true),'<hr>';
//格式化
array_walk($arr,function ($value,$key){
    echo $key,':',$value,'<br>';
});
echo '<hr>';

运行实例 »

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


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
Author's latest blog post