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, 1564🔥, 0💬
Popular Posts:
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...
How to convert JSON Objects to PHP Associative Arrays using the json_decode() function? Actually, JS...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...