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, ∼3687🔥, 0💬
Popular Posts:
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
Where to get the detailed description of the JSON.stringify() Function in JavaScript? Here is the de...
How to create a "Sign-up or Sign-in" user flow policy in my Azure AD B2C directory? If you want to b...
How to use the RSS Online Validator at w3.org? You can follow this tutorial to learn how to use the ...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...