Yes, you are misunderstanding how return values work
When you call a function, you must assign the value returned into a variable. Just running the function won't change the value you passed in, because the function is working with that variable in another
scope. Inside that function, where you are working with the variable $value, that isn't the same $value you were working with outside of the function. A copy was created and sent inside the function! Here is how you should write that code:
Code: Select all
$value = 0;
function writeName($name,$value)
{
echo "My Name Is " . $name . "";
$value = 3;
return $value;
}
$name = "Alex";
$returned = writeName($name,$value); //you must assign a variable here to get the result
print $returned; //and then get show the results from that variable here