Blogger Information
Blog 26
fans 0
comment 3
visits 19685
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
细说函数2019/9/28
西门吃雪
Original
601 people have browsed it
<?php
function a(...$d){ //...$d是剩余参数的意思,并且前面没有其他形参,所以在下面的实参列表里,4,5,8,10,2都给到了$c,形成一个一维的数组

$zz=1;//给一个初始值, 用在下面的乘法里

foreach($d as $cc){ //用数组循环函数,把数组里的数据提取出来
$zz*=$cc;//把数组里的数据提取出来之后,数据互相乘
}
 return $zz;//最后输出乘法的结果
    
}
echo a(4,5,9,10,2)//对应到上面的形参表达式,这里的4,5,8,10,2都会给到剩余参数里,因为在剩余参数前面没有其他的形参了



?>

运行效果

QQ截图20190929162326.jpg

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