Blogger Information
Blog 35
fans 0
comment 0
visits 26688
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数的基础操作
锋芒天下的博客
Original
789 people have browsed it

实例

<?php
//1、参数默认值
function sum($name='李四',$age=20){
    return '姓名:'.$name. '年龄:'.$age;
};
$res = sum('张三');
echo $res;  //姓名:张三  年龄:20

echo '<hr>';

//2. 实例演示剩余参数;
function sum2($a,$b,...$c){
    return $a+$b+array_sum($c);
};
echo sum2(20,30,40,23,34,53,23,23,12);  //258

echo '<hr>';

//3. 实际演示匿名函数,并调用外部数据;
$suer = '王五';

$a = function() use($suer){
    return $suer;
};

echo $a();
echo '<hr>';

//4. 实际演示call_user_func_array()的常用场景(忽略调用对象方法)
function sum3($x,$y){
    return $x+$y;
};
echo sum3(20,40);
echo '<hr>';
echo call_user_func_array('sum3',[30,40]);

echo '<hr>';

print_r(['a','b','c','e','f']);
echo '<hr>';
echo call_user_func_array('print_r',[['a','b','c','e','f']]);

运行实例 »

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


Correction status:qualified

Teacher's comments:在php中函数的作业非常的强大, 是一切知识点的基础
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