PHP中可变范围的问题

I have just written a program to check for the variable scopes in PHP. The code goes like this:

<?php
$value = 1;
function change_value(){
    if(some_condition){
        $value = 0;
        $asset = 1;
    }else{
        $asset = 0;
    }
    return $asset;
}
echo $value;
change_value();
echo $value;
?>

Now, the output of the above program is 11. How can I change the value of $value once it enters the function change_value() ?

Pass the parameter by reference:

<?php
$value = 1;
function change_value(&$value){
    if(/* some_condition */){
        $value = 0;
        $asset = 1;
    }else{
        $asset = 0;
    }
    return $asset;
}
echo $value; // echoes 1
$asset = change_value($value);
echo $value; // echoes 0
echo $asset; // echoes 0 or 1 depending on /* some_condition */
?>

Please don't use global ... even if some suggest it. It's bad. It let's the variable be accessable from all over the script and you will be very confused when you come upon the situation where you access $value in a different script you included and it acts different then...

What you're trying to do, goes against common principles, but.

$GLOBALS['value'] = 0;

Using this inside function will let you change that value, but I suggest you not to do this.

The way others have outlined, is far more right.