©
This document uses PHP Chinese website manual Release
(PHP 5, PHP 7)
variant_xor — Performs a logical exclusion on two variants
$left
, mixed $right
)Performs a logical exclusion.
left
The left operand.
right
The right operand.
Note:
对于所有变量运算函数,本函数的参数可以是 PHP 内置的类型(整数,字符串,浮点数,布尔型或者
NULL
),或者是一个 COM,VARIANT 或者 DOTNET 类的实例。PHP 内置类型将会使用和构造VARIANT类相同的规则转换成变量。COM 和 DOTNET 对象的值将会取其默认属性并被当成变量值使用。变量运算函数是同名函数在 COM 库中的外包;有关此类函数的更多信息参见 MSDN 库。PHP 函数命名有少许区别,例如 PHP 中的 variant_add() 对应于 MSDN 文档中的 VarAdd()。
If left is | If right is | then the result is |
---|---|---|
TRUE | TRUE | FALSE |
TRUE | FALSE | TRUE |
FALSE | TRUE | TRUE |
FALSE | FALSE | FALSE |
NULL | NULL | NULL |
[#1] tinelbarb at yahoo dot com [2010-08-30 00:21:11]
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 :-)
[#2] tinelbarb at yahoo dot com [2010-08-30 00:20:56]
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 :-)
[#3] tinelbarb at yahoo dot com dot RE-MO-VE dot ME [2010-08-30 00:20:39]
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 :-)