#native_company# #native_desc#
#native_cta#

Quick If

By Amit Arora
on August 21, 2001

Sometimes, while working in the HTML you need to print or manipulate a string, based upon certain values (mostly boolean). You could use

if (...) {
...
}
else {
...
}

How about this ….


function iif( $bool = true, $tstr = '', $fstr = '')
{
    if ($bool)
    {
        return( $tstr );
    }
    else
    {
        return( $fstr );
    }
}

I have used strings as return value, you may use integers or even abstract return value, depending on your need.

A example:


    echo iif( $loggedin, "Logged In", "Not Logged In" );

Any suggestions, comments are welcome …