我当前的项目使用 Laravel4。我的 Web 应用程序中有一个搜索功能。这是我的搜索功能代码,位于我的一个controller.php 文件中。
public function postBloodSearch(){
$blood_group = Input::get('blood_group');
$location = Input::get('location');
if(empty($blood_group and $location)){
return Redirect::route('donors')
->with('global','You have to enter both Blood Group and Location');
}
$result = Donor::where('blood_group','LIKE','%'.$blood_group.'%')->where('location','LIKE','%'.$location.'%')->get();
return View::make('bloodDonation.blood_array')->with('result',$result);
}
你可以看到,在我的代码中,我使用了内置于 empty 函数中的 php,而实际上我面临的是 出现以下错误
syntax error, unexpected 'and' (T_LOGICAL_AND), expecting ')'
我尝试了以下代码来解决这个问题(只需将 and 替换为 && )
if(empty($blood_group && $location)){.........}
现在抛出以下错误
syntax error, unexpected '&&' (T_LOGICAL_AND), expecting ')'
更新:相同的代码在我的本地服务器(Xampp 服务器)中运行得非常好。但是在我的实时服务器(我使用 Cpanel)中,它抛出了这些错误。
最佳答案
而不是
if(empty($blood_group and $location)){
尝试
if(empty($blood_group) and empty($location)){
在上面的调用中,您将 bool 值传递给 empty function
。错误原因提到on php docs
作为
Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
关于php - Laravel 语法错误,意外 'and' (T_LOGICAL_AND),期望 ')',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26081826/