phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


php Operators: Logic Operator

Tag: operator, Logic Operator   Category: PHP Basic
post: 08 Mar 2008 read: 732


PHP Operators Step By Step Tutorial - Part 11: Logic operator is the operator that is used to compare two values to be yielding of one value so that will get the result of true and false.

The table of Logic Operator

Operator Info Example Result
and or && and $a and $b
or
$a && $b
True if $a & $b is true.
or or (||) or $a or $b
$a || $b
True if $a or $b is true.
xor exclusive or $a xor $b True if one of $a or $b is correct, but not both.
! nor !$a True if $a is false
False if $a is true.

Fur further information, pay attention to the tables of the following:

The table of the Logic Operator Truth.

Operand
a
Operand
b
&&
$a && $b
||
$a || $b
xor
$a xor $b
!
!$a
true true true True false false
true false false True true false
false true false True true true
false false false False false true

Pay attention to the example of using logic operator at script as following:

File name: logicoperator.php


<html>
<head>
<title>Using Logic Operator</title>
</head>

<body>
<h1>Logic Operator</h1>
<pre>
$q = 16;
$r = 7;
$s = 17;
$t = 17;
</pre>
<?
$q = 16;
$r = 7;
$s = 17;
$t = 17;
$u = ($q > $r) and ($s > $t);
$v = ($q > $r) && ($s > $t);
$w = ($q > $r) or ($s > $t);
$x = ($q > $r) || ($s > $t);

$y = ($q > $r) xor ($s > $t);
$z = ($q < $r) xor ($s > $t);

$a = ($q > $r);
$b = !$a;
printf ("(q > r) and (s > t) = %d <br>",$u);
printf ("(q > r) && (s > t) = %d <br>",$v);
printf ("(q > r) or (s > t) = %d <br>",$w);
printf ("(q > r) || (s > t) = %d <br>",$x);
printf ("(q > r) xor(s > t) = %d <br>",$y);
printf ("(q < r) xor (s > t) = %d <br>",$z);
printf ("(q > r) and (s > t) = %d <br>",$u);
printf ("(q > r) = %d <br>",$a);
printf ("!a = %d <br>",$b);
?>
</body>
</html>

logic operator


Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting