note 99665 added to function.variant-xor
| From: | tinelbarb at yahoo dot com dot RE-MO-VE dot ME | Date: | Mon, 30 Aug 2010 07:20:39 +0000 |
| Subject: | note 99665 added to function.variant-xor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172154@lists.php.net to get a copy of this message | ||
I've been using a lot the VARIANT_XOR function (all the VARIANT functions ar cool) and I was
faceing the problem that some custom copilation of PHP, especially LAMP packs, doesn't have the
VARANT functions included, so the scripts halts.
I had to find an alternative for those who doesn't have an implamentation of VARIANT_XOR.
I'd love if somebody improve my "A_XOR_B" function by changing the name in
"VARIANT_XOR" and to run the original VARIANT_XOR function (being optimized) if it is
already in the PHP compilation, else run the custom XOR code.
<?php
function a_xor_b($a=0, $b=0) {
return ( ($a!=$b) && ($a||$b) ) ? TRUE : FALSE ;
}
?>
If using this function, make sure you use the same type for arguments ;-)
Here is a sample code using it:
<?php
if ( a_xor_b(strlen($column1)>0,strlen($column2)>0) ) {
$add_and='';
}
if ( !a_xor_b(strlen($column1)>0,strlen($column2)>0 ) && strlen($column1)>0 ) {
$add_and=' and ';
}
$some_sql_filter=$query_str.' having '.$column1.$add_and.$column2;
?>
The use of VARIANT_XOR was identical.
@PHP TEAM: the VARIANT set is so great :-)
----
Server IP: 69.147.83.197
Probable Submitter: 86.127.71.214
----
Manual Page -- http://www.php.net/manual/en/function.variant-xor.php
Edit -- https://master.php.net/note/edit/99665
Del: integrated -- https://master.php.net/note/delete/99665/integrated
Del: useless -- https://master.php.net/note/delete/99665/useless
Del: bad code -- https://master.php.net/note/delete/99665/bad+code
Del: spam -- https://master.php.net/note/delete/99665/spam
Del: non-english -- https://master.php.net/note/delete/99665/non-english
Del: in docs -- https://master.php.net/note/delete/99665/in+docs
Del: other reasons-- https://master.php.net/note/delete/99665
Reject -- https://master.php.net/note/reject/99665
Search -- https://master.php.net/manage/user-notes.php