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, 1254👍, 0💬
Popular Posts:
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
How To Use an Array as a Queue in PHP? A queue is a simple data structure that manages data elements...