Jump to content

[SOLVED] Either or but not both


soycharliente

Recommended Posts

How would you test if only one of something is empty but not both? This doesn't seem to be working.

 

<?php
$dollars = $_POST['dollars'];
$cents = $_POST['cents'];
$errors .= (empty($dollars) || empty($cents))
? "<br /><span class=\"error\">Check the price.</span>"
: FALSE;
?>

Link to comment
https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/
Share on other sites

Is XOR the same as ^?

 

Did you read the link:

 

Explanation:

 

An exclusive OR only evaluates to TRUE when exactly one operand is TRUE.

 

To extend your explanation, yes XOR is the same as ^.... but ^ is on the bitwise level, whereas XOR is a normal logical operator for any non-bitwise comparisons.

 

Bitwise:

echo "hallo" ^ "hello"; // Outputs the ascii values #0 #4 #0 #0 #0
// 'a' ^ 'e' = #4

 

Comparison, normal use:

if(!$var XOR !$var2) {
// if one is false and other is not false, but not both

Did you read the link:

 

Yes I did. Then went and did some more research on my own and came back with another question.

 

My apologies, I thought by '^' you were pointing towards Haku's post.  KingPhilip has posted a good explanation.    ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.