Tools, FAQ, Tutorials:
Returning an Array from a Function in PHP
How To Return an Array from a Function? in PHP?
✍: FYIcenter.com
You can return an array variable like a normal variable using the return statement. No special syntax needed. Here is a PHP script on how to return an array from a function:
<?php
function powerBall() {
$array = array(rand(1,55), rand(1,55), rand(1,55),
rand(1,55), rand(1,55), rand(1,42));
return $array;
}
$numbers = powerBall();
print("Lucky numbers: ".join(",",$numbers)."\n");
?>
This script will print:
Lucky numbers: 35,24,15,7,26,15
If you like those numbers, take them to buy a PowerBall ticket.
⇒ Local Variables in a Function in PHP
⇐ Defining an Array Argument as Reference in PHP
2016-12-18, ∼4236🔥, 0💬
Popular Posts:
How to add request body examples to my Azure API operation to make it more user friendly? If you hav...
How to use 'choose ... when ..." policy statements to control execution flows? If you want to contro...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
What is Azure API Management Publisher Dashboard? Azure API Management Publisher Dashboard is an Azu...
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...