
Originally Posted by
Hidden
he means:
PHP Code:
<?php
if($hi==TRUE)
echo ' hello ' ;
else
echo 'hi';
?>
I personally read simple if statements fine using this method:
bool ? if_value : false_value;
PHP Code:
echo ($hi==TRUE) ? 'hello' : 'hi';
But that's just me. If I'm using a system that will always only be one line, I'll do this method. If there's a possibility I'll put in more lines in the future, I'll use a longer statement just in case. However, for a function where it only takes a condition and returns true or false.. Like a function that checks if a user is a certain rank
PHP Code:
function check_rank($rank,$allowed_ranks) //$rank is needed, $allowed_ranks is optional array/PSL
{
if(strlen($rank)>0)
{
if(strlen($allowed_ranks)<1)
{
$allowed_ranks = 'Admin';
}
$allowed_ranks = ( count($allowed_ranks)>0 ? explode('|',$allowed_ranks) : $allowed_ranks );
$bool = if(preg_match('/'.$allowed_ranks.'/i',$rank)>0;
return $bool;
}
}
$permission_to_enter = check_rank($_SESSION['rank'],'Admin|Mod|Registered');
echo ( $permission_to_enter ? 'You May Pass.' : 'You Shall Not Pass!' );
Notice this line:
echo ( $permission_to_enter ? 'You May Pass.' : 'You Shall Not Pass!' );
There's really no need for further work on this line.It's simple, if the rank is allowed, say it's allowed. If not, say it's not allowed.
Simple, no? 
EDIT: Still, you all should look up and listen hard to Daevius, he pretty much taught me everything, so take me as a grain of salt in comparison. I'm just showing you all some other organization methods that you might personally like too ;)
It is always nice to keep decipherable code. I remember not too long ago I didn't understand the bool?true:false; method, and saw it as Chinese or something.. Now it makes more sense than english to me.. Do whatever is the best compromise between "best for you," and "best for the world," Always ;)