soycharliente Posted January 27, 2009 Share Posted January 27, 2009 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 More sharing options...
haku Posted January 27, 2009 Share Posted January 27, 2009 if((empty($dollars) && !empty($cents)) || (empty($cents) && !empty($dollars)) Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747759 Share on other sites More sharing options...
Maq Posted January 27, 2009 Share Posted January 27, 2009 Use XOR Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747760 Share on other sites More sharing options...
soycharliente Posted January 27, 2009 Author Share Posted January 27, 2009 Is XOR the same as ^? Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747764 Share on other sites More sharing options...
Maq Posted January 27, 2009 Share Posted January 27, 2009 Is XOR the same as ^? Did you read the link: Explanation: An exclusive OR only evaluates to TRUE when exactly one operand is TRUE. Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747773 Share on other sites More sharing options...
haku Posted January 27, 2009 Share Posted January 27, 2009 That's what I like about this site - there is always something else to learn. XOR is new to me, but I will definitely use it in the future. Much shorter than what I posted. Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747774 Share on other sites More sharing options...
Philip Posted January 27, 2009 Share Posted January 27, 2009 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 Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747783 Share on other sites More sharing options...
soycharliente Posted January 27, 2009 Author Share Posted January 27, 2009 Did you read the link: Yes I did. Then went and did some more research on my own and came back with another question. Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747784 Share on other sites More sharing options...
Maq Posted January 27, 2009 Share Posted January 27, 2009 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. Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-747813 Share on other sites More sharing options...
haku Posted January 27, 2009 Share Posted January 27, 2009 I thought he was pointing at my post too Link to comment https://forums.phpfreaks.com/topic/142663-solved-either-or-but-not-both/#findComment-748069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.