variant_xor

(PHP 5, PHP 7, PHP 8)

variant_xor2 つの variant の排他的論理和を計算する

説明

variant_xor(mixed $left, mixed $right): variant

排他的論理和を計算します。

パラメータ

left

左オペランド。

right

右オペランド。

注意:

variant に関するすべての計算用関数と同様、この関数のパラメータには PHP のネイティブ型 (整数、文字列、浮動小数点数、boolean あるいは null) あるいは COM、VARIANT、DOTNET クラスのインスタンスが使用できます。 PHP のネイティブ型は、variant クラスのコンストラクタと同じ方法で variant に変換されます。 COM オブジェクトおよび DOTNET オブジェクトはデフォルトプロパティの値を持っており、 これを variant の値として使用します。

variant に関する計算関数は、COM ライブラリの同名の関数のラッパーです。 これらの関数についての詳細な情報は、MSDN ライブラリでご確認ください。 PHP での関数名は微妙に異なります。たとえば、PHP での関数 variant_add() に対応する関数は、MSDN のドキュメントでは VarAdd() となります。

戻り値

Variant の XOR 規則
left right 結果
truetruefalse
truefalsetrue
falsetruetrue
falsefalsefalse
nullnullnull

エラー / 例外

失敗時に com_exception をスローします。

参考

  • variant_or() - 2 つの variant の論理和を計算する
  • variant_and() - 2 つの variant の論理積を計算し、結果を返す

add a note add a note

User Contributed Notes 3 notes

up
1
tinelbarb at yahoo dot com
14 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
-1
tinelbarb at yahoo dot com
14 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
-1
tinelbarb at yahoo dot com dot RE-MO-VE dot ME
14 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 :-)
To Top