View Single Post
02-18-2007, 10:53 PM
#1
Ali is offline Ali
Status: Junior Member
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Ali is on a distinguished road

  Old  do NOT use {} for single if-else statements..

hey mates, just browsed a couple of threads in this section and I got impression that most of the people are using wrong code/technique while using if or else statements..

for example if you are using "if" statement

if($x == 10) {

echo "it is 10";

} else {

echo"it is not 10";
}

now thats not a good approach since you have only one function being used in "if" and also in "else", so there is no need of using those brackets, you can use it someting like this..

if($x == 10)
echo "it is 10";
else
echo"it is not 10";

OR use ternary operator, e.g.

$myVar = condition ? if_condition_true : if_condition_false

thats just a note for beginners, since I found a couple of threads and saw their code, I though since they read these forums, it would be a good advice for beginners...

cheers