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, 1774🔥, 1💬
Popular Posts:
How To Control Vertical Alignment? By default, text in all table cells are aligned to the top vertic...
How To Protect Special Characters in Query String in PHP? If you want to include special characters ...
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...
Why am I getting this "Docker failed to initialize" error? After installing the latest version of Do...
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...