Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 returns in one function

I would like to return 2 different values with one function. These are my functions:

function example1 ($a) {
    return $result1;
    return $result2;
}

function example2 ($edit, $account, $value) {
    $config ($edit);
}

Like this I get $result1 in my $config-variable. But what do I need to do to get both returned values in my example1-function?

like image 624
Michiel Avatar asked Aug 26 '26 06:08

Michiel


2 Answers

This is probably the cleanest way to do this:

function example1($a)
{
    return array($result1, $result2)
}

// get both values
list($config1, $config2) = example1($a);

This will make $config = $result1 and $config2 = $result2.

like image 106
Logan Serman Avatar answered Aug 27 '26 20:08

Logan Serman


You can't return 2 variables in one function, you should return an array instead:

function example1 ($a) {
    $result[0] = 'something';
    $result[1] = 'something else';
    return $result;
}
like image 41
matino Avatar answered Aug 27 '26 19:08

matino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!