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, ∼3863🔥, 0💬
Popular Posts:
How to decode the id_token value received from Google OpenID Connect authentication response? Accord...
How To Open Standard Output as a File Handle in PHP? If you want to open the standard output as a fi...
How to attach console to a Running Container using the "docker container exec" command? I want to ge...
How to make application release build with Visual Studio 2017? If you want to make a final release b...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...