This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet24/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   20   21   22   23   24   25   26   27   ...   69
Bog'liq
PHP

Variables
|
31
The old value of
$black
is lost. Instead,
$black
is now another name for the value
that is stored in
$white
:
$big_long_variable_name = "PHP";
$short =& $big_long_variable_name;
$big_long_variable_name .= " rocks!";
print "\$short is $short\n";
print "Long is $big_long_variable_name\n";
$short is PHP rocks!
Long is PHP rocks!
$short = "Programming $short";
print "\$short is $short\n";
print "Long is $big_long_variable_name\n";
$short is Programming PHP rocks!
Long is Programming PHP rocks!
After the assignment, the two variables are alternate names for the same value.
Unsetting a variable that is aliased does not affect other names for that variable’s
value, though:
$white = "snow";
$black =& $white;
unset($white);
print $black;
snow
Functions can return values by reference (for example, to avoid copying large strings
or arrays, as discussed in Chapter 3):
function &ret_ref() { // note the &
$var = "PHP";
return $var;
}
$v =& ret_ref(); // note the &
Variable Scope
The
scope
of a variable, which is controlled by the location of the variable’s declara-
tion, determines those parts of the program that can access it. There are four types of
variable scope in PHP: local, global, static, and function parameters.
Local scope
A variable declared in a function is local to that function. That is, it is visible only to
code in that function (including nested function definitions); it is not accessible out-
side the function. In addition, by default, variables defined outside a function (called
global variables) are not accessible inside the function. For example, here’s a func-
tion that updates a local variable instead of a global variable:
function update_counter ( ) {
$counter++;
}
,ch02.15294 Page 31 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   ...   20   21   22   23   24   25   26   27   ...   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