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
2016-12-18, 1432👍, 0💬
Popular Posts:
How to Build my "sleep" Docker image from the Alpine image? I want the container to sleep for 10 hou...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How to add request URL Template Parameters to my Azure API operation 2017 version to make it more us...