This is my first php program!



Download 6,9 Mb.
Pdf ko'rish
bet36/69
Sana26.02.2022
Hajmi6,9 Mb.
#471647
1   ...   32   33   34   35   36   37   38   39   ...   69
Bog'liq
PHP

Casting Operators
Although PHP is a weakly typed language, there are occasions when it’s useful to
consider a value as a specific type. The casting operators,
(int)
,
(float)
,
(string)
,
(bool)
,
(array)
, and
(object)
, allow you to force a value into a particular type. To
use a casting operator, put the operator to the left of the operand. Table 2-8 lists the
casting operators, synonymous operands, and the type to which the operator changes
the value.
Casting affects the way other operators interpret a value, rather than changing the
value in a variable. For example, the code:
$a = "5";
$b = (int) $a;
Table 2-8. PHP casting operators
Operator
Synonymous operators
Changes type to
(int)
(integer)
Integer
(float)
(real)
Floating point
(string)
String
(bool)
(boolean)
Boolean
(array)
Array
(object)
Object
,ch02.15294 Page 43 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.
44
|
Chapter 2: Language Basics
assigns
$b
the integer value of
$a
;
$a
remains the string
"5"
. To cast the value of the
variable itself, you must assign the result of a cast back into the variable:
$a = "5"
$a = (int) $a; // now $a holds an integer
Not every cast is useful: casting an array to a numeric type gives
1
, and casting an
array to a string gives
"Array"
(seeing this in your output is a sure sign that you’ve
printed a variable that contains an array).
Casting an object to an array builds an array of the properties, mapping property
names to values:
class Person {
var $name = "Fred";
var $age = 35;
}
$o = new Person;
$a = (array) $o;
print_r($a);

Download 6,9 Mb.

Do'stlaringiz bilan baham:
1   ...   32   33   34   35   36   37   38   39   ...   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