PHP conditional syntax: less than

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: PHP programming  

To determine if a value is less than another value, use:

if ($var < 0)
echo "var is negative and non-zero";

To determine if a value is less than or equal to another value, use:

if ($var <= 0)
echo "var is negative";

 

2 Comments -


  1. abu said on January 21, 2010

    How do I check for non numerical characters i.e. abc etc i know its ok for numbers.

  2. Linker1988 said on January 19, 2011

    If you want to check a string you can use the function strlen()
    it will count how big a string is so for ex
    $Str = “abc”;
    $Count = strlen($Str);
    echo $Count;
    result will be 3

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -