CopyPastehas never been so tasty!

Compare integer using comparison operator in PHP

by anonymous

  • 0
  • 0
  • 0
81 views

 

 Orignal Source:http://codingvilla.com/compare-integer-comparison-operator-php-single-article-571.aspx

Integer Data Type:

 

In PHP integer is single-value type. Integers are whole numbers. Its range varies according to your platform. But you can use any number from -2,147,483,648 to +2,147,483,647. Integer can be written in decimal, octal and hexadecimal.

 

We can represent Decimal without zero, octal with a leading 0 and a sequence of digits from 0 to 7,hexadecimal with 0-9 and alphabets A-F. 

 

For example:

 

1998 (Decimal)
0755  (Octal) 
0xFF(hexadecimal)

 

Comparison operator:

 

By using Comparison operator we can compare two values in PHP.Comparison operator as its name shows allow to compare values.

 

Syntax:

 

$a == $b

 

 

Comparison operator in PHP:

 

To compare integers in PHP we use comparison operator. In the code below there in an example of comparing two integer values. If variable $a is equal to variable $b then print equal otherwise not equal.

 

 

Code:

 

 

<?php

$a=100;

$b=true;

echo "a = $a<br>";

echo "b = $b<br>";

if($a==$b)

   echo 'a "is equal to" b!';

else

echo 'a "is not equal to" b!';

?>

 

 

This is simple code to compare integer values using comparison operator in PHP.

 

This simple article tells that how we can compare integer values using comparison operator in PHP.

 

 

Add A Comment: