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, 1844🔥, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How to convert JSON Objects to PHP Associative Arrays using the json_decode() function? Actually, JS...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...