2013-10-31 38 views
-1

考慮我在PHP中大newbe,所以.. 我做了一些爭論誰做什麼功能,我想打電話給只有一個參數.. 這裏是我的測試:如何在php函數中調用精確參數?

public static function test($arg1,$arg2,$arg3) 
    { 

    $bob1 = "thats arg1"; 
    $bob2 = "thats arg2"; 
    $bob3 = "thats arg3"; 

    $arg1 = echo $bob1; 
    $arg2 = echo $bob2; 
    $arg3 = echo $bob3; 

    } 

現在我想致電$arg3,我怎樣才能撥打test($arg3);test(' ' , ' ' , $arg3)是否合法?還是有更好的做法?

+0

您不能使用_call_參數,您可以使用**參數列表調用_functions_ **。 – moonwave99

回答

1
public static function test($arg1='',$arg2='',$arg3='') 
{ 
if(!empty($arg1)){ 
    echo $arg1; 
    } 
    elseif(!empty($arg2)){ 
    echo $arg2; 
    } 
    elseif(!empty($arg3)){ 
    echo $arg3; 
    } 
    else{ echo 'no argu'; } 

} 

我認爲你的意思就像echo測試('','',$ arg3);

+0

感謝您的幫助請參閱我的編輯請 – albator

+0

親愛的更好的方式來傳遞數組,然後從索引檢查。 – Asif