2016-06-15 30 views
0

這裏是我的一塊PHP代碼,檢查返回值:如何在PHP函數

Excel::load(Input::file('file'), function ($reader) { 
    some_function(); 
}); 

我的問題是如何讓some_function的返回值(),並檢查它,如果它是真實的,在執行完Excel :: load()塊之後?但請不要使用try-catch-block!

回答

0

通過參考使用返回值參數,這樣就可以在回調

$returnValue = null; 
Excel::load(Input::file('file'), function ($reader) use (&$returnValue) { 
    $returnValue = some_function(); 
}); 
if ($returnValue) { 
    // Do stuff 
} 
+0

嗨,馬克,不幸的是這不工作的外部訪問它。之前,我做了if-check我做了一個var_dump($ returnValue),它給了我總是null :( –

+0

對不起我的壞。我用&運算符:) –