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, ∼3361🔥, 1💬
Popular Posts:
What is Azure API Management Developer Portal? Azure API Management Developer Portal is an Azure Web...
When using "@(...)" expressions in XML attributes as part of an policy statement, do I need to worry...
How to attach console to a Running Container using the "docker container exec" command? I want to ge...
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference ...
Where can I download the EPUB 2.0 sample book "The Problems of Philosophy" by Lewis Theme? You can f...