![]() |
iif Function - what's using for ?
well , i want to have any easy example with explaining for ( iif ) function , please :)
regards ;) |
for asigning variables?
as an example PHP Code:
|
It's "a shortcut" for
PHP Code:
PHP Code:
|
Xenon & KirbyDE
thanks , i understood it :) regards :classic: |
you're welcome :)
|
i think it's official name is inline if conditional, not sure though :)
|
aka Inline If
|
Insert If?
:D |
Terniary operator I believe.
|
yep, that's the general terminus for the ? : construct
|
Does PHP not directly support ?: ?
|
it does but the IIF's are purdier ;)
|
Quote:
|
In iif(), the third argument is optional, which can make it more convenient every now and then.
|
not that i ever needed that special behaviour of iif ;)
|
iff() is really useful when used within queries, it's such a simple but effective functions. Vb staffs always do great jobs.
|
isn't IIF actually a php function?
guess not, i've been using it all this time and didn't even know lol |
No, it's a vBulletin function defined in functions.php
|
Quote:
|
Quote:
|
The function is kind of redundant, the only time it helps is with clarity for new coders. I just tend to use in my scripts :)
PHP Code:
|
Quote:
From functions.php PHP Code:
|
actually my editor highlights it as well, as i'm highlighting some vb functions ^^
|
iif() is handy for true and false returns. However if you use it to test and then pass data, if the data chunk is large, it may be much more inefficent then a plain old if/else.
|
I did just notice one major problem with it, but it's the design of PHP (and most other languages) that causes it: the ternary operator supports lazy evaluation (only evaluates what is needed based on the condition), whereas the iif() function evaluates all of its arguments regardless of the condition's value.
An excerpt of my code that demonstrates the problem: PHP Code:
|
Ah yes and here's the example I had written and realized the overhead it created just moving a copy of the data, I overlooked that it executed the addslashes() function as well even if it was not needed.
This is very inefficient, in some cases $data could have been 1MB... PHP Code:
|
as the name of the varibles vb defined, this is absolutely useful for boolean vale the best.
|
All times are GMT. The time now is 11:28 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|