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, 1991🔥, 1💬
Popular Posts:
What is the standard to map XML repeating elements to JSON values? There seems to be no industry sta...
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How To Set session.gc_divisor Properly in PHP? As you know that session.gc_divisor is the frequency ...
How To Use an Array as a Queue in PHP? A queue is a simple data structure that manages data elements...