导航

php函数形参传值与传引用

Posted on 2018-03-20 16:52  sishuisufeng  阅读(351)  评论(0编辑  收藏  举报

传值

-------------------------------------------------

function example( $m ){
    $m = $m * 5 + 10;
    echo "在函数内:\$m = ".$m;
}
$m = 1;
example( $m ) ;  
echo "<p>在函数外:\$m = $m <p>" ; 

 

传引用

-------------------------------------------------

function example( &$m ){
$m = $m * 5 + 10;
echo "在函数内:\$m = ".$m;
}
$m = 1;
example( $m ) ;
echo "<p>在函数外:\$m = $m <p>" ;