Blogger Information
Blog 77
fans 0
comment 0
visits 55256
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数,使用到剩余参数来实现_0928
Jet的博客
Original
687 people have browsed it

实例

<?php
//不定参数的乘积
function sum($a,$b,...$c)
{
    array_push($c,$a,$b);
    return array_product($c);
}
echo sum(1,2,3,4,5,6,7,8,9);


//array_product : 乘积计算函数 
//array_push    : 向数组尾部添加元素
//array_unshift : 向数组头部添加元素

运行实例 »

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

 

Correction status:qualified

Teacher's comments:换个姿势:echo sum(...range(1,5))
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