Output variables


If I remember correctly, in ASP.NET you can define out variables by something like this.

void function123(string bla, out string bla2, out string bla3){bla2=“lol”;}

So when you call tthe function, everything that happens to variables in terms of changing values can be extracted.

string var1 = null;
function123(null,out string var1, null);
//var1 now equals to “lol”

I’m wondering if there is anything similar in PHP.

Sorry for my n00b English :stuck_out_tongue:

maybe its just best not to complicate and return an array…thanks anyway.

Thanks Jake :slight_smile: Saved me few lines of code :slight_smile:

Sure you can :slight_smile: Use the & operator.

function addUpAndSet($varOne, $varTwo, &$varThree){
    $varThree = $varOne + $varTwo;
$something = 0;
addUpAndSet(1, 2, $something);
echo $something;

This means that the variable isn’t copied and sent to the function, but the actual variable is sent with the same address in memory etc. In other words, a change on the sent variable inside the function happens to the variable inside it.