downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Printer> <variant_sub
[edit] Last updated: Fri, 18 Sep 2009

view this page in

variant_xor

(PHP 5)

variant_xorPerforms a logical exclusion on two variants

Описание

mixed variant_xor ( mixed $left , mixed $right )

Performs a logical exclusion.

Параметри

left

The left operand.

right

The right operand.

Забележка: Както и при останалите функции за вариантна аритметика, параметрите на тази функция могат да бъдат както от прост тип в PHP (целочислен, низ, плаващ, булев или NULL), така и инстанция някой от класовете COM, VARIANT или DOTNET. Простите типове в PHP ще бъдат преобразувани до варианти според същите правила, използвани от конструктора на класа VARIANT. Обектите COM и DOTNET ще вземат стйността на свойството им по подразбиране и ще използват тази стойност като стойност на варианта.
Функциите за вариантна аритметика са опаковки на именуваните по подобен начин функции в библиотеката COM; за повече информация относно тези функции се консултирайте с библиотеката MSDN. Функциите в PHP са именувани малко по-различно; например variant_add() в PHP отговаря на VarAdd() в документацията на MSDN.

Връщани стойности

Variant XOR Rules
If left is If right is then the result is
TRUETRUEFALSE
TRUEFALSETRUE
FALSETRUETRUE
FALSEFALSEFALSE
NULLNULLNULL

Вж. също

  • variant_or() - Performs a logical disjunction on two variants
  • variant_and() - Performs a bitwise AND operation between two variants



Printer> <variant_sub
[edit] Last updated: Fri, 18 Sep 2009
 
add a note add a note User Contributed Notes variant_xor - [3 notes]
up
0
tinelbarb at yahoo dot com
2 years ago
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 :-)
up
0
tinelbarb at yahoo dot com
2 years ago
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 :-)
up
0
tinelbarb at yahoo dot com dot RE-MO-VE dot ME
2 years ago
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 :-)

 
show source | credits | sitemap | contact | advertising | mirror sites