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, 1563🔥, 0💬
Popular Posts:
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to register and get an application ID from Azure AD? The first step to use Azure AD is to regist...