This is my first php program!



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

Operator Associativity
Associativity defines the order in which operators with the same order of precedence
are evaluated. For example, look at:
2 / 2 * 2
,ch02.15294 Page 36 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.
Expressions and Operators
|
37
The division and multiplication operators have the same precedence, but the result
of the expression depends on which operation we do first:
2/(2*2) // 0.5
(2/2)*2 // 2
The division and multiplication operators are left-associative; this means that in
cases of ambiguity, the operators are evaluated from left to right. In this example, the
correct result is 2.
Implicit Casting
Many operators have expectations of their operands—for instance, binary math
operators typically require both operands to be of the same type. PHP’s variables can
store integers, floating-point numbers, strings, and more, and to keep as much of the
type details away from the programmer as possible, PHP converts values from one
type to another as necessary.
The conversion of a value from one type to another is called
casting
. This kind of
implicit casting is called
type juggling
in PHP. The rules for the type juggling done by
arithmetic operators are shown in Table 2-4.
Some other operators have different expectations of their operands, and thus have
different rules. For example, the string concatenation operator converts both oper-
ands to strings before concatenating them:
3 . 2.74 // gives the string 32.74
You can use a string anywhere PHP expects a number. The string is presumed to
start with an integer or floating-point number. If no number is found at the start of
the string, the numeric value of that string is 0. If the string contains a period (
.
) or
upper- or lowercase
e
, evaluating it numerically produces a floating-point number.
For example:
"9 Lives" – 1; // 8 (int)
"3.14 Pies" * 2; // 6.28 (float)
"9 Lives." – 1; // 8 (float)
"1E3 Points of Light" + 1; // 1001 (float)
Table 2-4. Implicit casting rules for binary arithmetic operations

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   25   26   27   28   29   30   31   32   ...   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