Using if...else more effectively
I am quite sure that most of you are confident users of the programm flow structurer if...else. In this first issue, I am trying to explain you how can use if…else more effectively respective that you can minimize your code to its minimum. The best is if I show you a simple example to show you what I mean.
function isEmpty($string)
{
if ($string == null || trim($string) == "")
{
return true;
}
return false;
}
I don’t know but maybe some of you already know how to write this code snipplet in a shorter way. If not just look how I do it.
function isEmpty($string)
{
return $string == null || trim($string) == "";
}
« Make Google to Your own Napster! // 8-Core Mac Officially Announced! »
5 comments so far
Peti
30. Mar 07 16:08
Kauderwelsch :p
Martin Labuschin
31. Mar 07 17:10
Is this PHP?
There is a function called empty() which does the same
Tom S. Weber
01. Apr 07 15:43
Yes sure Martin. It’s only for demonstrating purposes… I could also named it
function foo()Martin Labuschin
02. Apr 07 10:37
Ah, ok. Sorry
sysspoof
22. Oct 07 10:11
I can’t recommend your example since I think that the example isn’t nice for the programmers eye… think about a big code snipped. Additionally allow me to mention that not all programmers are aware of this syntax. So it’s perhaps more confusing then helpful… but that is just my opinion
Cheers
sys aka pat
Write your comment
Leave a Reply