php终止函数运行都用return;吗?break
exit
这些行不?还有什么可以终止hello()的?<?php
function hello(){
return;  //hello函数不执行下去了。
echo "hello";
} function world(){
echo "world";
} hello();
world();
?>

解决方案 »

  1.   

    return表示返回值
    exit直接退出
    break是用于跳出循环的其实不加return,函数执行到最后也是会自动退出的。
      

  2.   


    <?php
    $need_js="no"; function need_js(){
    global $need_js;
    if($need_js=="no"){
    return;
    }
    } function hello(){
    need_js(); //如何用一个函数来判断是否执行下去?
    echo "hello";
    } function world(){
    echo "world";
    } hello();
    world();
    ?>
      

  3.   

        $need_js="no";    function need_js(){
            global $need_js;
            if($need_js=="no"){
                return 0;
            }
        }    function hello(){
           if(need_js() ) {    //如何用一个函数来判断是否执行下去?
               echo "hello";
           }
        }    function world(){
            echo "world";
        }    hello();
        world();
      

  4.   


    exit()和die()是直接结束所有后续程序的运行
    return 只是结束当前function