If you really hate this tut so much and think you could do it better, then make your own tut.
Printable View
other tips would be to learn how to use
die();
continue();
PHP Code:<?php
function mathAdd($num1, $num2){
$answer = strval($num1) + strval($num2);
return $answer;
}
?>
I personally read simple if statements fine using this method:
bool ? if_value : false_value;
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 rankPHP Code:echo ($hi==TRUE) ? 'hello' : 'hi';
Notice this line: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!' );
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? :w00t:
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 ;)
if statements depends on how they are needed
i generally use inside echo or variables declerations... since it would be a waste of time to do a full if statement.Code:$this == true ? 'TRUE' : 'FALSE'
and others like
ofCode:if ($this == TRUE ) Die();
else {
echo 'it is not true';
echo 'probably false then';
}
Code:foreach ($this as $this1 => $this2) {
if ($this2 == TRUE) continue;
echo 'FALSE STUFF';
}