Comparison Operators for If/Else Statements

So far you have just been using the equal comparison operator, but conditional statements are really
checking to see if a statement evaluates to true, not if something is equal. You can also check to see
if something is not equal to something, less than something else, more than something, and so on.
Strings that consist of numbers are converted to numeric before the test except for the identical ===.

Comparison Operators
OPERATOR DESCRIPTION EXAMPLE
== Is equal to 6==’6’ returns true
=== Is identical to (including the type cast) 6===’6’ returns false
!= Is not equal to 6!=5 returns true
<> Is not equal to 6<>5 returns true
< Is less than 6<5 returns false
> Is greater than 6>5 returns true
<= Is less than or equal to 6<=5 returns false
>= Is greater than or equal to 6>=5 returns true
Some
Related Posts:
  • File Manipulation 11.3. File Manipulation There may be times when you don't want to store information in a database and may want to work directly with a file instead. An example is a logfile that tracks when your application can't co… Read More
  • Using Cookie Authentication PHP Store authentication status in a cookie or as part of a session. When a user logs insuccessfully, put their username in a cookie. Also include a hash of the username and a secretword so a user can't just make up an authentic… Read More
  • Create Dynamic Database Access Objects Some simple PHP that makes for a surprisingly robust script <?php require_once( "DB.php" ); $dsn = 'mysql://root:password@localhost/books'; $db =& DB::Connect( $dsn, array() ); if (PEAR::isError($db)) { die($db->g… Read More
  • PHP Functions A function is a named sequence of code statements that can optionally accept parameters and return a value. A function call is an expression that has a value; its value is the returned value from the function. PHP provid… Read More
  • Php Mysql Image upload <?php // 1. Gem modtagne formulardata i variabler: $navn = $_POST['navn']; $alder = $_POST['alder']; $postnr = $_POST['postnr']; $mail = $_POST['mail']; $billede = $_FILES['profilbillede']; $password = $_PO… Read More
  • Defining Functions There are already many functions built into PHP. However, you can define your own and organize your code into functions. To define your own functions, start out with the function statement: function some_function([argumen… Read More
  • Convert CSV to PHP Every once in a while, I have a static list of values that I don't want to put into a database, but that I do want to use in my PHP application. That static data can come from a variety of sources, but often it's in a s… Read More
  • Showing the Browser and IP Address Here is a simple page that prints out the browser string and the IP address of the HTTP request. Create a file with the following content in your web directory, name it something like example.php3, and load it in your bro… Read More
  • Php Directory Functions chdir — Change directory chroot — Change the root directory closedir — Close directory handle dir — Return an instance of the Directory class getcwd — Gets the current working directory opendir — Open directory handle read… Read More
  • PHP Web-Related Variables PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP's global symbol table or … Read More
  • PHP Data Types PHP provides four primitive data types: integers, floating point numbers, strings, and booleans. In addition, there are two compound data types: arrays and objects.  Integers Integers are whole numbers. The range… Read More
  • Including and Requiring PHP Files To make your code more readable, you can place your functions in a separate file. Many PHP add-ons that you download off the Internet contain functions already placed into files that you simply include in your PHP program… Read More
  • PHP - Echo <?php $myiString = "Hi!"; echo $myiString; echo "<h5>I love PHP!</h5>"; ?>   Display: Hi! I love  PHP!  A simple form example     1 <html> 2 <head> 3 <title&g… Read More
  • Length of a String The length property of a string is determined with the strlen( ) function, which returns the number of eight-bit characters in the subject string: integer strlen(string subject) We used strlen( ) earlier in the chapter t… Read More
  • PHP Configuration Directives Although the focus of this book is application security, there are a few configuration directives with which any security-conscious developer should be familiar. The configuration of PHP can affect the behavior of the cod… Read More