返回an和chain的最后一个值

Is there a way to return the last value in an and chain? I can do this is in Javascript but php seems to just return a boolean value.

E.g.

$message = ($error && "First error") || ($error1 && "Second error");

$message will be 1 instead of "First error". Assuming $error = true;

var error = true;
var error1 = true;

var message = (error && "First") || (error1 && "Second");

alert(message);

error = false;

message = (error && "First") || (error1 && "Second");

alert(message);

</div>

try to use XOR (0 XOR 1 ) || (0 XOR 1) == 1 || 1 == 1

You can use ternary operator for your condition.

 <?php
   $error1 = true;
   $message = $error ? "First error" : ($error1 ? "Second error" : "");
   echo $message;
?>

live demo1 : https://eval.in/792139

live demo2 : https://eval.in/792134

Assuming that i do understand you correctly, just out of curiosity - what is wrong with doing this?

$error1 = true;
$error = true;
if($error) {
    echo "first message";
}
if($error1) {
    echo "second message";
}