I know other mate already provided the solution, so i am adding my answer for future aspects.
Suppose you have two functions getHello() and getGoodbye() with different definition same purpose.
// function one
function getHello(){
return "Hello";
}
// function two
function getGoodbye(){
echo "Goodbye";
}
//now call getHello() function
$helloVar = getHello();
Result:
'Hello' // return 'hello' and stored value in $helloVar
//now call getGoodbye() function
$goodbyeVar = getGoodbye();
Result:
'Goodbye' // echo 'Goodbye' and not stored in $goodbyeVar
echo $helloVar; // "Hello"
echo $goodbyeVar; // Goodbye
Result:
'GoodbyeHello'
// now try same example with this:
echo $helloVar; // "Hello"
//echo $goodbyeVar; // Goodbye
Result should be same because getGoodbye() already echo'ed the result.
Now Example with Your Code:
function myfunction($test){
//global $test;
echo $test;
}
function myfunction2($test){
//global $test;
return $test;
}
myfunction('test'); // test
myfunction2('test'); // noting
//You need to echo myfunction2() as i mentioned in above.
echo myfunction2('test'); // test
Why it's not working in your code?:
you need to declare variable as Global before assigning the values like:
global $test;
$test = "blah";
myfunctionpart of a class? or just simple written function