Page 1 of 1

A question about function()

Posted: 17 Dec 2020 20:42
by zakhar
Hello, dear forum!

I have the following question:

Code: Select all

 $a = 0;
 func($a);
 echo 3 $a;
 
 function func($a){
    echo 1 $a;
    $a += 1;
    echo 2 $a;
    return $a;
 }
In the code above how can I get the $a in "echo 3 $a;" to be the same as in the "echo 2 $a;" ?
The problem in other words: I can submit $a from "$a = 0;" through the "func($a);" into the "function func($a){}",
but not backwards from "function func($a){}" to the "echo 3 $a;".

Re: A question about function()

Posted: 17 Dec 2020 20:48
by highend
By assigning your func() call result to $a

$a = func($a);

Re: A question about function()

Posted: 17 Dec 2020 22:07
by zakhar
Wow!
Thank you, highend!