This is my first php program!


Statements and Semicolons



Download 6,9 Mb.
Pdf ko'rish
bet12/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   8   9   10   11   12   13   14   15   ...   69
Bog'liq
PHP

Statements and Semicolons
A statement is a collection of PHP code that does something. It can be as simple as
a variable assignment or as complicated as a loop with multiple exit points. Here is
,ch02.15294 Page 17 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.
18
|
Chapter 2: Language Basics
a small sample of PHP statements, including function calls, assignment, and an
if
test:
echo "Hello, world";
myfunc(42, "O'Reilly");
$a = 1;
$name = "Elphaba";
$b = $a / 25.0;
if ($a == $b) { echo "Rhyme? And Reason?"; }
PHP uses semicolons to separate simple statements. A compound statement that
uses curly braces to mark a block of code, such as a conditional test or loop, does not
need a semicolon after a closing brace. Unlike in other languages, in PHP the semico-
lon before the closing brace is not optional:
if ($needed) {
echo "We must have it!"; // semicolon required here
} // no semicolon required here
The semicolon is optional before a closing PHP tag:
if ($a == $b) { echo "Rhyme? And Reason?"; }
echo "Hello, world" // no semicolon required before closing tag
?>
It’s good programming practice to include optional semicolons, as they make it eas-
ier to add code later.
Whitespace and Line Breaks
In general, whitespace doesn’t matter in a PHP program. You can spread a state-
ment across any number of lines, or lump a bunch of statements together on a single
line. For example, this statement:
raise_prices($inventory, $inflation, $cost_of_living, $greed);
could just as well be written with more whitespace:
raise_prices (
$inventory ,
$inflation ,
$cost_of_living ,
$greed
) ;
or with less whitespace:
raise_prices($inventory,$inflation,$cost_of_living,$greed);
You can take advantage of this flexible formatting to make your code more read-
able (by lining up assignments, indenting, etc.). Some lazy programmers take advan-
tage of this free-form formatting and create completely unreadable code—this isn’t
recommended.
,ch02.15294 Page 18 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:
1   ...   8   9   10   11   12   13   14   15   ...   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