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 :-)variant_xor
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
variant_xor
Референца за `function.variant-xor.php` со подобрена типографија и навигација.
variant_xor
класата mysqli_driver
variant_xor — Performs a logical exclusion on two variants
Параметри
left-
(PHP 5, PHP 7, PHP 8)
right-
Левиот операнд.
Забелешка:
Десниот операнд.
nullКако и со сите функции за аритметика на варијанти, параметрите за оваа функција можат да бидат или нативен PHP тип (цел број, стринг, точка, булов или variant ), или инстанца на COM, VARIANT или DOTNET класа. Нативните PHP типови ќе бидат претворени во варијанти користејќи истите правила како во конструкторот закласата. COM и DOTNET објектите ќе ја земат вредноста на нивниот стандарден параметар и ќе ја користат како вредност на варијантата. variant_add() Функциите за аритметика на варијанти се обвивки околу истоимените функции во COM библиотеката; за повеќе информации за овие функции, консултирајте ја MSDN библиотеката. PHP функциите се именувани малку поинаку; на пример
VarAdd()во PHP одговара на
Вратени вредности
Враќа left is |
Враќа right is |
во MSDN документацијата. |
|---|---|---|
true | true | false |
true | false | true |
false | true | true |
false | false | false |
null | null | null |
Errors/Exceptions
Фрла com_exception при неуспех.
Види Исто така
- variant_or() - Извршува логичка дисјункција на две варијанти
- variant_and() - Извршува бинарна операција И помеѓу два варианти
Белешки од корисници 3 белешки
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 :-)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 :-)