phpeveryday.com

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


PHP Operators: Operator Priority

Tag: operator, Operator Priority   Category: PHP Basic
post: 08 Mar 2008 read: 909


PHP Operators Step By Step Tutorial - Part 15: For the complex expression which entangled of many operator and operand, the operators will be done by PHP according to its priority.

Example:


x = 24 - 20 / 4

For that, 24/4 will be done first, then the result of the division will become the reduction of 24 so that yields 19 non 1. That thing is caused by the priority of operator/higher than operator -.

The table of operator priority:

Priority Operators Workmanship sequence
1 new non-associative
2 [ right
3 !
~
++
-- (int) (float) (string) (array)
(object) @
right
4 *
/
%
left
5 +
-
.
left
6 <<
>>
left
7 <
<=
>
>=
non-associative
8 ==
!=
===
!==
non-associative
9 & left
10 ^ left
11 | left
12 && left
13 || left
14 ?: left
15 =
+=
-=
*=
/=
.=
%=
&=
|=^=
<<=
>>=
left
16 print right
17 and left
18 xor left
19 or left
20 , left

Operator in the same line have the same priority. Pay attention to the example of using string operator at script as following:

File name: operatorpriority.php


<html>
<head>
<title>Operator Priority</title>
</head>

<body>
<pre>
$a = 25;
$b = 10;
$c = 15;
$result = $a + $b * $c / 3;
</pre>
<h3>Processed by PHP</h3>
<?
$a = 25;
$b = 10;
$c = 15;
$result = $a + $b * $c / 3;
echo ("Result = $result");
?>
</body>
</html>
php operator priority


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


615
posting