Jump to content

Question about returning values


Fira

Recommended Posts

You could
[code]
<?php
$result = myfunc_that_returns_array ();
$lifeleft = $result[0];
$epgain = $result[1];
$apgain = $result[2];
?>[/code]

or

[code]
<?php
list ($lifeleft, $epgain, $apgain) = myfunc_that_returns_array ();
?>
[/code]
As an alternative to returning an array, you can also pass the vars by reference
[code]<?php
function myfunc_that_not_return_array (&$x, &$y, &$z) {
        // calculation code here
    $x = 42;
    $y = 0.05;
    $z = -30;
}

$lifeleft = $epgain = $apgain = 0;  // initialise vars

myfunc_that_not_return_array ($lifeleft, $epgain, $apgain);  // call function

printf ('%d, %0.2f, %d', $lifeleft, $epgain, $apgain); // --> 42, 0.05, -30
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.