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, 1746🔥, 1💬
Popular Posts:
How to send an FTP request with the urllib.request.urlopen() function? If an FTP server supports ano...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to start Visual Studio Command Prompt? I have Visual Studio 2017 Community version with Visual C...