Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Placing an IF statement into a variable

I want to place an if statement into a variable in order to reduce the lines of code... for example I want to do this:

$empty = if(empty($_POST['username']) && empty($_POST['password']))
if($empty){ // echo message; 
}
elseif(!$empty){ ///echo message; 
}

Can something like the above be produced? Or am I making things too complex?

like image 267
Sohail Arif Avatar asked Sep 17 '26 22:09

Sohail Arif


1 Answers

Just omit the if:

$empty = empty($_POST['username']) && empty($_POST['password']);
like image 124
hanzi Avatar answered Sep 19 '26 13:09

hanzi