This is my first php program!


Expressions and Operators



Download 6,9 Mb.
Pdf ko'rish
bet28/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   24   25   26   27   28   29   30   31   ...   69
Bog'liq
PHP

Expressions and Operators
|
35
Table 2-3. PHP operators
P
A
Operator
Operation
19
N
new
Create new object
18
R
[
Array subscript
17
R
!
Logical NOT
R
~
Bitwise NOT
R
++
Increment
R
--
Decrement
R
(int)
,
(double)
,
(string)
,
(array)
,
(object)
Cast
R
@
Inhibit errors
16
L
*
Multiplication
L
/
Division
L
%
Modulus
15
L
+
Addition
L
-
Subtraction
L
.
String concatenation
14
L
<<
Bitwise shift left
L
>>
Bitwise shift right
13
N
<
,
<=
Less than, less than or equal
N
>
,
>=
Greater than, greater than or equal
12
N
==
Value equality
N
!=
,
<>
Inequality
N
===
Type and value equality
N
!==
Type and value inequality
11
L
&
Bitwise AND
10
L
^
Bitwise XOR
9
L
|
Bitwise OR
8
L
&&
Logical AND
7
L
||
Logical OR
6
L
?:
Conditional operator
5
L
=
Assignment
L
+=
,
-=
,
*=
,
/=
,
.=
,
%=
,
&=
,
|=
,
^=
,
~=
,
<<=
,
>>=
Assignment with operation
4
L
and
Logical AND
3
L
xor
Logical XOR
2
L
or
Logical OR
1
L
,
List separator
,ch02.15294 Page 35 Wednesday, March 13, 2002 11:42 AM


This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
36
|
Chapter 2: Language Basics
Number of Operands
Most operators in PHP are binary operators; they combine two operands (or expres-
sions) into a single, more complex expression. PHP also supports a number of unary
operators, which convert a single expression into a more complex expression.
Finally, PHP supports a single ternary operator that combines three expressions into
a single expression.
Operator Precedence
The order in which operators in an expression are evaluated depends on their rela-
tive precedence. For example, you might write:
2 + 4 * 3
As you can see in Table 2-3, the addition and multiplication operators have different
precedence, with multiplication higher than addition. So the multiplication happens
before the addition, giving
2 + 12
, or
14
, as the answer. If the precedence of addition
and multiplication were reversed,
6 * 3
, or
18
, would be the answer.
To force a particular order, you can group operands with the appropriate operator in
parentheses. In our previous example, to get the value
18
, you can use this expression:
(2 + 4) * 3
It is possible to write all complex expressions (expressions containing more than a
single operator) simply by putting the operands and operators in the appropriate
order so that their relative precedence yields the answer you want. Most program-
mers, however, write the operators in the order that they feel makes the most sense
to programmers, and add parentheses to ensure it makes sense to PHP as well. Get-
ting precedence wrong leads to code like:
$x + 2 / $y >= 4 ? $z : $x << $z
This code is hard to read and is almost definitely not doing what the programmer
expected it to do.
One way many programmers deal with the complex precedence rules in program-
ming languages is to reduce precedence down to two rules:
• Multiplication and division have higher precedence than addition and subtraction.
• Use parentheses for anything else.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   24   25   26   27   28   29   30   31   ...   69




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish