Returning values
Values are returned by using the optional return statement. Any type may be returned, including arrays and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called.
<?php function square($num) { return $num * $num; } echo square(4); // outputs '16'. ?>
A function can not return multiple values, but similar results can be obtained by returning an array.
<?php function small_numbers() { return array (0, 1, 2); } $arr = small_numbers(); echo $arr[0]."<br>"; echo $arr[1]."<br>"; echo $arr[2]."<br>"; ?>