Tools, FAQ, Tutorials:
Passing Arrays to Function in PHP
Can You Pass an Array into a Function? in PHP?
✍: FYIcenter.com
You can pass an array into a function in the same as a normal variable. No special syntax needed. Here is a PHP script on how to pass an array to a function:
<?php
function average($array) {
$sum = array_sum($array);
$count = count($array);
return $sum/$count;
}
$numbers = array(5, 7, 6, 2, 1, 3, 4, 2);
print("Average: ".average($numbers)."\n");
?>
This script will print:
Average: 3.75
⇒ Passing Arrays by Values to Functions in PHP
⇐ Defining an Argument as a Reference in PHP
2023-04-06, ∼3526🔥, 1💬
Popular Posts:
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How To Read Data from Keyboard (Standard Input) in PHP? If you want to read data from the standard i...