Tools, FAQ, Tutorials:
Function with Undefined Number of Arguments in PHP
How To Define a Function with Any Number of Arguments? in PHP?
✍: FYIcenter.com
If you want to define a function with any number of arguments, you need to:
Here is a PHP script on how to handle any number of arguments:
<?php
function myAverage() {
$count = func_num_args();
$args = func_get_args();
$sum = array_sum($args);
return $sum/$count;
}
$average = myAverage(102, 121, 105);
print("Average 1: $average\n");
$average = myAverage(102, 121, 105, 99, 101, 110, 116, 101, 114);
print("Average 2: $average\n");
?>
This script will print:
Average 1: 109.33333333333 Average 2: 107.66666666667
⇒ Reading and Writing Files in PHP
⇐ Specifying Argument Default Values in PHP
2016-12-04, ∼2943🔥, 0💬
Popular Posts:
How To Protect Special Characters in Query String in PHP? If you want to include special characters ...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
How To Create an Array with a Sequence of Integers or Characters in PHP? The quickest way to create ...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...