PHPBuilder - Quick If



RSS Twitter
Tips Application Architecture

Quick If

by: Amit Arora
|
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 ...

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Amit Arora

Comment:



Comment:

(Maximum characters: 1200). You have characters left.