PHP鐨勮繑鍥炲

鍐呭鎽樿
鍊奸氳繃浣跨敤鍙夌殑杩斿洖璇彞杩斿洖銆傚彲浠ヨ繑鍥炲寘鎷暟缁勫拰瀵硅薄鐨勪换鎰忕被鍨嬨傝繑鍥炶鍙ヤ細绔嬪嵆涓鍑芥暟鐨勮繍琛岋紝骞朵笖灏嗘帶鍒舵潈浜ゅ洖璋冪敤璇ュ嚱鏁扮殑浠g爜琛屻
鏂囩珷姝f枃
杩斿洖鍊
鍊奸氳繃浣跨敤鍙夌殑杩斿洖璇彞杩斿洖銆傚彲浠ヨ繑鍥炲寘鎷暟缁勫拰瀵硅薄鐨勪换鎰忕被鍨嬨傝繑鍥炶鍙ヤ細绔嬪嵆涓鍑芥暟鐨勮繍琛岋紝骞朵笖灏嗘帶鍒舵潈浜ゅ洖璋冪敤璇ュ嚱鏁扮殑浠g爜琛屻傛洿澶氫俊鎭 return()銆


Example #1 return() 鐨勪娇鐢

<?php
function square($num)
{
    return $num * $num;
}
echo square(4);   // outputs '16'.
?>
鍑芥暟涓嶈兘杩斿洖澶氫釜鍊硷紝浣嗗彲浠ラ氳繃杩斿洖涓涓暟缁勬潵寰楀埌绫讳技鐨勬晥鏋溿


Example #2 杩斿洖涓涓暟缁勪互寰楀埌澶氫釜杩斿洖鍊

<?php
function small_numbers()
{
    return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
?>
浠庡嚱鏁拌繑鍥炰竴涓紩鐢紝蹇呴』鍦ㄥ嚱鏁板0鏄庡拰鎸囨淳杩斿洖鍊肩粰涓涓彉閲忔椂閮戒娇鐢ㄥ紩鐢ㄦ搷浣滅 & 锛


Example #3 浠庡嚱鏁拌繑鍥炰竴涓紩鐢

<?php
function &returns_reference()
{
    return $someref;
}

$newref =& returns_reference();
?>
鏈夊叧寮曠敤鐨勬洿澶氫俊鎭, 璇锋煡鐪嬪紩鐢ㄧ殑瑙i噴銆

浠ヤ笂灏辨槸PHP鐨勮繑鍥炲肩殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=91