批改状态:合格
老师批语:还是补之前的作业呢, 建议之前的作业先放放, 尽可能跟上进度, 否则二头都顾不上, 之前的作业 , 可以放在双休日集中完成
<?php
//默认参数
function office($cpu = "i5")
{
return "这台电脑默认cpu: $cpu \n";
}
echo office();
echo '<hr>';
//2. 实例演示剩余参数;
function reverse1($a, ...$arr)
{
return $a + array_sum($arr);
}
echo reverse1(5,12,212,3243,32323);
echo '<hr>';
// 3实际演示匿名函数,并调用外部数据;
$name="php";
$example = function () use ($name) {
var_dump($name);
};
echo $example();
echo '<hr>';
//4. 实际演示call_user_func_array()的常用场景(忽略调用对象方法)
//调用回调函数,并把一个数组参数作为回调函数的参数
//(1)普通使用:动态调用普通函数时,参数和调用方法名称不确定的时候很好用
function sayEnglish($fName, $content) {
echo 'I am ' . $content;
}
function sayChinese($fName, $content, $country) {
echo $content . $country;
echo "<br>";
}
function user() {
$args = func_get_args();
call_user_func_array($args[0], $args);
}
echo user('sayChinese', '我是', '中国人');
echo user('sayEnglish', 'Chinese');
?>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号