This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet41/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   37   38   39   40   41   42   43   44   ...   69
Bog'liq
PHP


With the ternary conditional operator, it looks like this:
'.($active ? 'yes':'no').'' ?>
Compare the syntax of the two:
if (
expression
)
true_statement
else
false_statement
(
expression
) ?
true_expression
:
false_expression
The main difference here is that the conditional operator is not a statement at all.
This means that it is used on expressions, and the result of a complete ternary
expression is itself an expression. In the previous example, the
echo
statement is
inside the
if
condition, while when used with the ternary operator, it precedes the
expression.
switch
It often is the case that the value of a single variable may determine one of a num-
ber of different choices (e.g., the variable holds the username and you want to do
something different for each user). The
switch
statement is designed for just this
situation.
,ch02.15294 Page 48 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.

Download 6,9 Mb.

Do'stlaringiz bilan baham:
48
|
Chapter 2: Language Basics



Last Name:Lee


Please log in.

Because
if
is a statement, you can chain them:
if ($good)
print('Dandy!');
else
if ($error)
print('Oh, no!');
else
print("I'm ambivalent...");
Such chains of
if
statements are common enough that PHP provides an easier syn-
tax: the
elseif
statement. For example, the previous code can be rewritten as:
if ($good)
print('Dandy!');
elseif ($error)
print('Oh, no!');
else
print("I'm ambivalent...");
The ternary conditional operator (
?:
) can be used to shorten simple true/false tests.
Take a common situation such as checking to see if a given variable is true and print-
ing something if it is. With a normal
if
/
else
statement, it looks like this:
1   ...   37   38   39   40   41   42   43   44   ...   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