Submit Tips/Quickies

Application Architecture : Miscellaneous

Quick If

Submitted By: Amit Arora
Date: 08/21/01 18:15

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 ...


Comments:
Re: Quick Ifbiggus08/30/01 10:03
Better solution already exists in PHPRyan Holmes08/29/01 18:52
quick IFSeb Frost08/28/01 15:26
PHP Built in FunctionsJosh B08/23/01 09:01
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.