Você está na página 1de 44

PHP Programming with MySQL (second edition) by Don

Gosselin, Diana Kokoska, obert !asterbrooks ("S#$%&'( )*+%,%


-'+*%.-+.%,, "S#$%&,( ,%-'+*%.-+.%')
e/erence( htt0(11www20h02net1man3al1en1langre/20h0
4ha0ter &( Getting started with PHP
5hat is PHP6
PHP( Hy0erte7t Pre0rocessor, or PHP, is an o0en%so3rce, ser8er%side 0rogramming
lang3age2 PHP is s0eci/ically designed to /ill the ga0 between static H9ML 0ages and
/3lly dynamic 0ages, s3ch as those generated thro3gh 4G" code2 PHP is embedded
directly in the :H9ML so3rce code2
5hat do yo3 need to write yo3r PHP scri0ts6
;o3 will write yo3r PHP scri0ts in a basic te7t editor2 9o r3n the PHP scri0t, yo3 will
need an <9P client to 30load the PHP so3rce code /iles to a 5eb ser8er and ha8e access
to a browser to 8iew the 5eb 0ages on the "nternet2
4reating #asic PHP Scri0ts
=a8aScri0t and PHP are both re/erred to as embedded lang3ages beca3se code /or both
lang3ages is embedded within a 5eb 0age (either an H9ML or :H9ML doc3ment)2 ;o3
ty0e this code directly into a 5eb 0age as a se0arate section2 >ltho3gh =a8aScri0t code
can be added to standard 5eb 0age doc3ments that ha8e an e7tension o/ 2html, a 5eb
0age doc3ment containing PHP code m3st ha8e an e7tension o/ 20h02 5hene8er a re?3est
is made /or a doc3ment with an e7tension o/ 20h0, the 5eb ser8er sends the /ile to the
scri0ting engine /or 0rocessing2 9he scri0ting engine then 0rocesses any PHP code it
enco3nters2 >ltho3gh PHP /iles 3se an e7tension o/ 20h0, they can contain the same
H9ML or :H9ML elements yo3 wo3ld /ind in a static 5eb 0age2 9he scri0ting engine
ignores any non%PHP code and only 0rocesses the PHP code it /inds within PHP code
blocks2 9he 5eb ser8er then ret3rns the res3lts o/ the PHP scri0t and any H9ML or
:H9ML elements /o3nd in the PHP /ile to the client, where the /ile is rendered by the
client@s 5eb browser2
$A9!( PHP code is ne8er sent to a client@s 5eb browserB only the res3lting 5eb 0age
that is generated /rom the PHP code and H9ML or :H9ML elements /o3nd within the
PHP /ile are ret3rned to the client2
4reating PHP 4ode #locks
;o3 write PHP scri0ts within code declaration blocks, which are se0arate sections on a
5eb 0age that are inter0reted by the scri0ting engine2 9here are /o3r ty0es o/ code
declaration blocks yo3 can 3se to write PHP(
&2 Standard PHP scri0t delimiters
C2 9he Dscri0tE element
'2 Short PHP scri0t delimiters
.2 >SP%style scri0t delimiters
&2 Standard PHP Scri0t Delimiters
9he standard method o/ writing PHP code declaration blocks is to 3se the D60h0 and 6E
scri0t delimiters2 > delimiter is a character or se?3ence o/ characters 3sed to mark the
beginning and end o/ a code segment2 5hen the scri0ting engine enco3nters the D60h0
and 6E scri0t delimiters, it 0rocesses any code between the delimiters as PHP2 9he
indi8id3al lines o/ code that make 30 a PHP scri0t are called statements2
D60h0
StatementsB
6E
$otice that PHP statement ends in a semicolon2 9he scri0ting engine ignores white s0ace
within code blocks2 (5hite s0ace F s0aces, tabs, and newlines)
$A9!( the PHP Gro30 o//icially recommends that yo3 3se standard PHP scri0t
delimiters to write PHP code declaration blocks2 Ane reason is that standard PHP scri0t
delimiters are g3aranteed to be a8ailable on any 5eb ser8er that s300orts PHP2
(#oth short PHP scri0t delimiters and >SP%style scri0t delimiters can be disabled2)
Howe8er, the 0rimary reason /or 3sing standard PHP scri0t delimiters is that they are the
only method that is com0letely com0liant with :ML2
(See e7am0le cha0terG,&G,&20h0)
C2 9he Dscri0tE !lement
> second o0tion /or creating PHP code blocks is to 3se the :H9ML Dscri0tE element2
5hen the Dscri0tE element is 3sed with PHP, yo3 m3st assign a 8al3e o/ HPHPI to the
lang3age attrib3te o/ the Dscri0tE element to identi/y the code block is PHP2 5hen the
PHP scri0ting engine enco3nters a Dscri0tE element with H0h0I assigned to its lang3age
attrib3te, it 0rocesses any code within the element as PHP on the ser8er be/ore ret3rning
the 5eb 0age2
Dscri0t lang3ageFJ0h0JE
statementB
D1scri0tE
$A9!( Like the standard PHP scri0t delimiters, the Dscri0tE element is always a8ailable
on any 5eb ser8er that s300orts PHP2 Kn/ort3nately, the Dscri0tE element@s lang3age
attrib3te is de0recated in :H9ML2 <3rther, the scri0ting engine ignores Dscri0tE
elements that incl3de the ty0e attrib3te, which is re?3ired /or com0atibility with both the
strict and transitional D9Ds2 <or this reason, yo3 cannot 8alidate doc3ments that incl3de
PHP Dscri0tE elements2
(See e7am0le cha0terG,&G,&20h0)
'2 Short PHP Scri0t Delimiters
> sim0li/ied method o/ writing PHP code declaration blocks is to 3se the short D6 and 6E
scri0t delimiters2 Short PHP scri0t delimiters are similar to standard PHP scri0t
delimiters, e7ce0t they do not incl3de J0h0J in the o0ening delimiter2
D6
statementsB
6E
$A9!( Knlike the D6 0h0 6E scri0t delimiters and the Dscri0tE element, which are always
a8ailable on any 5eb ser8er that s300orts PHP, the short D6 and 6E delimiters can be
disabled in a 5eb ser8er@s 0h02ini con/ig3ration /ile2 #eca3se a 5eb ser8er on which
yo3r PHP scri0t will r3n might not always be 3nder yo3r control, the PHP Gro30
disco3rages the 3se o/ short delimiters2
(See e7am0le cha0terG,&G,&20h0)
.2 >SP%Style Scri0t Delimiters
Some 5eb de8elo0ers 0re/er to 3se the >SP%style scri0t delimiters o/ DL and LE to
de8elo0 PHP scri0ts2
DL
statementsB
LE
$A9!( Like short PHP scri0t delimiters, >SP%style scri0t delimiters are com0liant with
:H9ML, incl3ding the strict D9D, b3t not with :ML2 >SP%style scri0t delimiters can
also be enabled or disabled in the 0h02ini con/ig3ration /ile, so yo3 sho3ld not 3se them
3nless yo3 are s3re they are enabled on any 5eb ser8ers on which yo3r PHP scri0ts will
r3n2
MSee e7am0le cha0terG,&G,&20h0N
Knderstanding <3nctions
MSee e7am0le cha0terG,&G,C20h0N
Dis0laying Scri0t es3lts
9o ret3rn the scri0t res3lts to the client, yo3 m3st 3se an JechoJ statement, or the J0rintJ
statement2 JechoJ and J0rintJ are not /3nctions, they are PHP 0rogramming lang3age
constr3ct2 > 0rogramming lang3age constr3ct re/ers to a b3ilt%in /eat3re o/ a
0rogramming lang3age2 9he JechoJ and J0rintJ statements are nearly identical, b3t they
ha8e some di//erences2 <or e7am0le, the 0rint statement ret3rns a 8al3e o/ & i/ it is
s3ccess/3l or a 8al3e o/ , i/ it is not s3ccess/3l, while the echo statement does not ret3rn a
8al3e2
$A9!( kee0 in mind that yo3 can 3se the e7act same synta7 with the 0rint statement that
yo3 3se with the echo statement2
D60h0
0rint J9his te7t is dis0layed 3sing a 0rint statement2JB
6E
<or both echo and 0rint statements, yo3 need to incl3de a te7t string that contains the te7t
that will a00ear in the 5eb browser2 > literal string is te7t that is contained within do3ble
or single ?3otation marks2
D60h0
echo J9his te7t is dis0layed 3sing echo statement with do3ble ?3oteJB
echo O9his te7t is dis0layed 3sing echo with single ?3oteOB
0rint J9his te7t is dis0layed 3sing 0rint statement with do3ble ?3oteJB
0rint O9his te7t is dis0layed 3sing 0rint with single ?3oteOB
6E
9he echo and 0rint statements s300ort m3lti0le arg3ments2
D60h0
echo J9his te7t is dis0layed with m3lti0le arg3ments2J, JSecond arg3mentJ, O9hird
arg3ment2JB
6E
$A9!( ;o3 can also 3se 0arentheses with the echo and 0rint statements in the same
manner that yo3 3se them with /3nctions2
D60h0
echo (J<irst arg3ment, J, JSecond arg3ment, J, J9hird arg3ment2 J)B
6E
4reating M3lti0le 4ode Declaration #locks
;o3 can incl3de as many PHP scri0t sections as yo3 want within a doc3ment2 Howe8er,
when yo3 incl3de m3lti0le scri0t sections in a doc3ment, yo3 m3st incl3de a se0arate
code declaration block /or each section2
DhtmlE
DheadEDtitleEM3lti0le #locksD1titleE
D1headE
DbodyE
Dh&EM3lti0le Scri0t SectionsD1h&E
DhCE<irst Scri0t SectionD1hCE
D60h0
echo JD0EA3t03t /rom the /irst scri0t section2D10EJB
6E
DhCESecond Scri0t SectionD1hCE
D60h0
echo JD0EA3t03t /rom the second scri0t section2D10EJB
6E
D1bodyE
D1htmlE
DhtmlE
DheadEDtitleEPHP !n8ironment "n/oD1titleE
D1headE
DbodyE
Dh&EPHP !n8ironment "n/oD1h&E
D0E0h08ersion() /3nction ret3rns the 8ersion o/ PHP
D60h0
echo 0h08ersion()B
6E
D10E
D0EPendG8ersion() /3nction ret3rns the 8ersion n3mber o/ the Qend !ngine, which is
PHP@s scri0ting engine
D60h0
echo PendG8ersion()B
6E
D10E
D0EiniGget() /3nction ret3rns the 8al3e assigned to a directi8e in the 0h02ini con/ig3ration
/ile2 ;o3 need to 0ass the name o/ a directi8e to the iniGget() /3nction, s3rro3nded by
?3otation marks2 !2g2 iniGget(Jma7Ge7ec3tionGtimeJ)
D60h0
echo iniGget(Jma7Ge7ec3tionGtimeJ)B
6E
second2D10E
D1bodyE
D1htmlE
4ase Sensiti8ity in PHP
Knlike :H9ML and =a8aScri0t, PHP is case insensiti8e2 ;o3 can 3se any o/ the
/ollowing 8ersions o/ the echo statement witho3t recei8ing an error message(
D60h0
echo JD0ELine one2 Dbr 1EJB
!cho JLine two2Dbr 1EJB
!4HA J and Line three2 D10EJB
6E
$A9!( !7ce0tions to PHP@s case insensiti8ity incl3de 8ariable and constant names,
which are case sensiti8e2
>dding 4omments to a PHP Scri0t
4omments are lines yo3 0lace in yo3r code that do not get e7ec3ted, b3t 0ro8ide hel0/3l
in/ormation2
PHP s300orts two kinds o/ comments( line comments and block comments2
> line comment a3tomatically terminates at the end o/ the line in which it is inserted2 9o
create a line comment, add either two /orward slashes (11) or the 0o3nd symbol (R) be/ore
the te7t yo3 want to 3se as a comment2 9he 11 or R characters instr3ct the scri0ting engine
to ignore all te7t immediately /ollowing the characters to the end o/ the line2
#lock comments allow m3lti0le lines o/ comment te7t to be added2 ;o3 create a block
comment by adding a /orward slash and an asterisk (1S) be/ore the start o/ the te7t that
yo3 want incl3ded in the block, and adding an asterisk and a /orward slash (S1) a/ter the
last characters in the block2 >ny te7t or lines between the o0ening 1S characters and the
closing S1 characters are ignored by the PHP engine2
D60h0
1S 9his is a
#lock comment2
S1
echo JDh&E4ommentD1h&EJB 11 line comment here
11 this is a line comment too
R another line comment2
6E
Ksing Tariables and 4onstants
> 8ariable is act3ally a s0eci/ic location in the com03ter@s memory2 9o 3se a 8ariable in a
0rogram, yo3 /irst ha8e to write a statement that creates the 8ariable and assigns it a
name2
$aming Tariables
9he name yo3 assign to a 8ariable is called an identi/ier2
"denti/iers m3st begin with a dollar sign (U)2
"denti/iers may contain 300ercase and lowercase letters, n3mbers, or 3nderscores
(G)2 9he /irst character a/ter the dollar sign m3st be a letter2
"denti/iers cannot contain s0aces2
"denti/iers are case sensiti8e2
Declaring and "nitialiPing Tariables
#e/ore yo3 can 3se a 8ariable in yo3r code, yo3 ha8e to create it2 9he 0rocess o/
s0eci/ying and creating a 8ariable name is called declaring the 8ariable2 9he 0rocess o/
assigning a /irst 8al3e to a 8ariable is called initialiPing the 8ariable2 Some 0rogramming
lang3ages allow yo3 to /irst declare a 8ariable witho3t initialiPing it2 Howe8er, in PHP,
yo3 m3st declare and initialiPe a 8ariable in the same statement2
U8ariableGname F 8al3eB
UMy$ame F JDonJB
Uetirement>ge F V-B
USales9otal F ,B
U43stArder F .,B
USales9otal F U43stArderB
Dis0laying Tariables
9o dis0lay a 8ariable with the echo statement, yo3 sim0ly 0ass the 8ariable name to the
echo statement, b3t witho3t enclosing it in ?3otation marks2
UToting>ge F &+B
echo UToting>geB
"/ yo3 want to dis0lay te7t strings and 8ariables in the same statement, yo3 can 0ass them
to the echo statement as indi8id3al arg3ments, se0arated by commas2
echo JD0E9he legal 8oting age is J, UToting>ge, J2D10EJB
;o3 can also incl3de 8ariable names inside a te7t string, altho3gh the res3lts yo3 see on
the screen de0end on whether yo3 3se do3ble or single ?3otation marks2 "/ yo3 3se
do3ble ?3otation marks, the 8al3e assigned to the 8ariable will a00ear2
echo JD0E9he legal 8oting age is UToting>ge2 D10EJB
#y contrast, i/ yo3 3se a 8ariable name in a te7t string enclosed by single ?3otation
marks, the name o/ the 8ariable will a00ear (not the 8al3e o/ the 8ariable)2
echo OD0E9he legal 8oting age is UToting>ge2D10EOB
Modi/ying Tariables
;o3 can modi/y the 8ariable@s 8al3e at any 0oint in a scri0t2
USales9otal F .,B 11 declare and initialiPe 8ariable
echo JD0ESales 9otal is UUSales9otalD10EJB
USales9otal F -,B 11 change the 8al3e o/ the 8ariable
echo JD0ESales 9otal is now UUSales9otalD10EJB
De/ining 4onstants
> constant contains in/ormation that does not change d3ring the co3rse o/ 0rogram
e7ec3tion2 ;o3 can think o/ a constant as a 8ariable with a static 8al3e2
4onstant names do not begin with a dollar sign (U)2 "n addition, it is common 0ractice to
3se all 300ercase letters /or constant names2 9o declare and initialiPe a constant, yo3 m3st
3se the de/ine() /3nction2
de/ine(J4A$S9>$9G$>M!J, 8al3e)B
de/ine(JD!<>KL9GL>$GK>G!J, J!nglishJ)B
de/ine(JTA9"$GG>G!J, &+)B
#y de/a3lt, constant names are case sensiti8e, as are 8ariables2
$A9!( yo3 can make constant names case insensiti8e by 0assing a #oolean 8al3e o/
9K! as a third arg3ment to the de/ine() /3nction2
de/ine(JD!<>KL9GL>$GK>G!J, J!nglishJ, 9K!)B
$A9!( Standard 0rogramming con8ention is to 3se all 300ercase letters /or constant
names, so yo3 sho3ld a8oid making yo3r constant names case insensiti8e2
9o dis0lay constant, yo3 can 0ass a constant name to the echo statement in the same
manner as 8ariables2
echo JD0E9he legal 8oting age is J, TA9"$GG>G!, J2D10EJB
echo JD0E9he legal 8oting age is TA9"$GG>G!2D10EJB
5orking with Data 9y0es
> data ty0e is the s0eci/ic category o/ in/ormation that a 8ariable contains2
PHP s300orts /i8e 0rimiti8e data ty0es(
Data 9y0e Descri0tion
"nteger n3mbers 9he set o/ all 0ositi8e and negati8e
n3mbers and Pero, with no decimal 0laces2
<loating W0oint n3mbers Positi8e or negati8e n3mbers with decimal
0laces or n3mbers written 3sing
e70onential notation2
#oolean > logical 8al3e o/ Htr3eI or H/alseI
String 9e7t s3ch as JHello 5orldJ
$KLL >n em0ty 8al3e, also re/erred to as a
$KLL 8al3e
9he PHP lang3age also s300orts re/erence, or com0osite, data ty0es, which can contain
m3lti0le 8al3es or com0le7 ty0es o/ in/ormation2
9he two re/erence data ty0es s300orted by the PHP lang3age are arrays and obXects2
PHP is a loosely ty0ed 0rogramming lang3age2 Loose ty0ing is also known as dynamic
ty0ing beca3se the data ty0e /or a 8ariable can change a/ter it has been declared2
U4hangingTariable F JHello 5orldJB 11 String
U4hangingTariable F +B 11 "nteger n3mber
U4hangingTariable F -2'V*B 11 <loating%0oint n3mber
U4hangingTariable F 9K!B 11 #oolean
U4hangingTariable F $KLLB 11 $KLL
$A9!( by contrast, 4, 4YY, =a8a are strongly ty0ed 0rogramming lang3ages2 Strong
ty0ing is also known as static ty0ing beca3se the data ty0e /or a 8ariable will not change
a/ter it has been declared2
$3meric Data 9y0es
PHP s300orts two n3meric data ty0es( integers and /loating%0oint n3mbers2
"ntegers are 0ositi8e and negati8e n3mbers and Pero, with no decimal 0laces (%C-,, %&', ,,
C, V, &,, &,, and &,,,,)2
> /loating%0oint n3mber contains decimal 0laces or is written in e70onential notation2
!70onential notation, or scienti/ic notation, is a shortened /ormat /or writing 8ery large
n3mbers or n3mbers with many decimal 0laces (%V2&V, %.2., '2&*, 2-C, &,2-, C2,e&&,
'2,!&,)2

Mcha0terG,&G,'20h0N
#oolean Tal3es
> #oolean 8al3e is a 8al3e o/ Htr3eI or H/alseI2
;o3 can 3se the integer 8al3e & to indicate a #oolean 8al3e o/ 9K! and , to indicate a
#oolean 8al3e o/ <>LS!2
"n PHP 0rogramming, yo3 can only 3se the words 9K! or <>LS! to indicate #oolean
8al3es2 PHP then con8erts the 8al3es 9K! and <>LS! to the integers & and ,2
Mcha0terG,&G,.20h0N
D60h0
Ue0eat43stomer F tr3eB 11 or 9K!
echo JD0Ee0eat 43stomer( Ue0eat43stomerD10EJB 11 re0eat c3stomer dis0lay &
U$3mG0ositi8e F C,B
i/ (U$3mG0ositi8e) Z
echo JD0E$3m 0ositi8e( U$3mG0ositi8eD10EJB
[
U$3mGnegati8e F %C,B
i/ (U$3mGnegati8e) Z
echo JD0E$3m negati8e( U$3mGnegati8eD10EJB
[ else Z
echo JD0E$3mGnegati8e is a <>LS! condition( U$3mGnegati8e D10EJB
[
U$3mGPero F ,B
i/ (U$3mGPero) Z
echo JD0E$3m Pero( U$3mGPeroD10EJB
[ else Z
echo JD0E$3mGPero is a <>LS! condition( U$3mGPero D10EJB
[
Ue0eatG0l3s& F Ue0eat43stomer Y &B
echo JD0Ee0eat 0l3s&( Ue0eatG0l3s&D10EJB
6E
>rrays
>n array is a set o/ data re0resented by a single 8ariable name2
;o3 3se arrays when yo3 want to store gro30s or lists o/ related in/ormation in a single,
easily managed location2
Declaring and "nitialiPing "nde7ed >rrays
"n PHP, yo3 can create n3merically inde7ed arrays and associati8e arrays2 (>ssociati8e
arrays will be disc3ssed in later cha0ter)2
>n element re/ers to a single 0iece o/ data that is stored within an array2
>n inde7 is an element@s n3meric 0osition within the array2
$A9!( #y de/a3lt, the n3mbering o/ elements within a PHP array starts with an inde7
n3mber o/ Pero (,)2
;o3 create an array 3sing the array() constr3ct or by 3sing the array name and brackets2
UarrayGname F array(data,, data&, dataC, data')B
Ar
UarrayGnameMN F data,B
UarrayGnameMN F data&B
UarrayGnameMN F dataCB
UarrayGnameMN F data'B
$A9!( 3nlike in 8ariables, the 0receding statements in arrays do not o8erwrite the
e7isting 8al3es2 "nstead, each 8al3e is assigned to the UarrayGnameMN array as a new
element 3sing the ne7t consec3ti8e inde7 n3mber2
$ote( Most 0rogramming lang3ages re?3ire that all elements in an array be o/ the e7act
same data ty0e2 "n PHP, the 8al3es assigned to di//erent elements o/ the same array can be
o/ di//erent data ty0es2
UHoteleser8ation F array(
JMy $ameJ, 11 g3est name (string)
C, 11 R o/ nights (integer)
+)2)-, 11 0rice 0er night (/loating%0oint)
tr3e)B 11 nonsmoking room (#oolean)
>ccessing !lement "n/ormation
9o /ind o3t the total n3mber o/ elements in an array, 3se the co3nt() /3nction2 ;o3 0ass to
the co3nt() /3nction the name o/ the array whose elements yo3 want to co3nt2
echo JD0E$3mber o/ elements in My>rray J, co3nt(UMy>rray), JDbr 1EJ,
J$3mber o/ elements in Hoteleser8ation array J, co3nt(UHoteleser8ation), JD10EJB
PHP incl3des the 0rintGr(), 8arGe70ort(), and 8arGd3m0() /3nctions, which yo3 can 3se to
dis0lay or ret3rn in/ormation abo3t 8ariables2 9hese /3nctions are most 3se/3l with arrays
beca3se they dis0lay the inde7 and 8al3e o/ each element2 ;o3 0ass to each /3nction the
name o/ an array (or other ty0e o/ 8ariable)2
PrintGr(UMy>rray)B
9he 0rintGr() /3nction does not incl3de any :H9ML /ormatting tags, so the array
elements are dis0layed as a contin3o3s string o/ te7t2 9o dis0lay the array elements on
indi8id3al lines, 3se D0reE tags2
echo JD0ED0reEJB
0rintGr(UMy>rray)B
echo JD10reED10EJB
Modi/ying !lements
;o3 modi/y 8al3es in e7isting array elements in the same /ashion as yo3 modi/y 8al3es in
a standard 8ariable, e7ce0t that yo3 incl3de the inde7 /or an indi8id3al element o/ the
array2
UMy>rrayMCN F JMore dataJB
UMy>rrayM&N F JLess dataJB
>8oiding >ssignment $otation Pit/alls
;o3 ha8e learned three di//erent assignment synta7es2
a) Tariable assignment
UMyTar F JHelloJB
b) >ssign new element to an array
UMy>rrayMN F JHelloJB
c) e0lace the 8al3e o/ an e7isting element in an array
UMy>rrayM,N F JMore HelloJB
Mcha0terG,&G,-20h0N
D60h0
UMy>rray F array(Jdata,J, Jdata&J, JdataCJ)B
UHoteleser8ation F array(
JMy $ameJ, 11 g3est name (string)
C, 11 R o/ nights (integer)
+)2)-, 11 0rice 0er night (/loating%0oint)
tr3e)B 11 nonsmoking room (#oolean)
UMy>rrayMN F Jdata'JB
UMy>rrayMN F Jdata.JB
UMy>rrayMN F Jdata-JB
1S to /ind the total n3mber o/ elements in an array, 3se the co3nt() /3nction2 S1
echo JD0E$3mber o/ elements in My>rray J, co3nt(UMy>rray), JDbr 1EJ,
J$3mber o/ elements in Hoteleser8ation array J, co3nt(UHoteleser8ation), JD10EJB
echo JD0E9here are J, co3nt(UMy>rray), J elements in My>rray2D1PED0EJB
echo JUMy>rrayM,NDbr 1EJB
echo JUMy>rrayM&NDbr 1EJB
echo JUMy>rrayMCNDbr 1EJB
echo JUMy>rrayM'NDbr 1EJB
echo JUMy>rrayM.NDbr 1EJB
echo JUMy>rrayM-ND10EJB
1S Modi/ying elements S1
UMy>rrayMCN F JMore dataJB
UMy>rrayM&N F JLess dataJB
1S 3se 0rintGr(), 8arGe70ort(), and 8arGd3m0() /3nctions S1
echo JD0ED0reEJB
0rintGr(UMy>rray)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy>rray)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy>rray)B
echo JD10reED10EJB
1S 3se 0rintGr(), 8arGe70ort(), and 8arGd3m0() /3nctions in 8ariableS1
UMyData F JHelloJB
echo JD0ED0reEJB
0rintGr(UMyData)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMyData)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMyData)B
echo JD10reED10EJB
UMy$3m F ',B
echo JD0ED0reEJB
0rintGr(UMy$3m)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy$3m)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy$3m)B
echo JD10reED10EJB
UMy#oolean9r3e F tr3eB
echo JD0ED0reEJB
0rintGr(UMy#oolean9r3e)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy#oolean9r3e)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy#oolean9r3e)B
echo JD10reED10EJB
UMy#oolean<alse F /alseB
echo JD0ED0reEJB
0rintGr(UMy#oolean<alse)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy#oolean<alse)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy#oolean<alse)B
echo JD10reED10EJB
6E
#3ilding !70ressions
>n e70ression is a literal 8al3e or 8ariable (or a combination o/ literal 8al3es, 8ariables,
o0erators, and other e70ressions) that can be e8al3ated by the PHP scri0ting engine to
0rod3ce a res3lt2
;o3 3se o0erands and o0erators to create e70ressions in PHP2
A0erands are 8ariables and literals contained in an e70ression2
> literal is a static 8al3e s3ch as a string or a n3mber2
A0erators are symbols, s3ch as the addition o0erator (Y) and m3lti0lication o0erator (S),
which are 3sed in e70ressions to mani03late o0erands2
PHP o0erator ty0es
9;P! D!S4"P9"A$
>rray Per/orms o0erations on arrays
>rithmetic Per/orms mathematical calc3lations
>ssignment >ssigns 8al3es to 8ariables
4om0arison 4om0ares o0erands and ret3rns a #oolean
8al3e
Logical Per/orms #oolean o0erations on #oolean
o0erands
S0ecial Per/orms 8ario3s tasksB these o0erators do
not /it within other o0erator categories
String Per/orms o0erations on strings
PHP o0erators are 3nary, binary, and ternary2
> 3nary o0erator re?3ires a single o0erand either be/ore or a/ter the o0erator2
UMy$3mberYYB
> binary o0erator re?3ires an o0erand be/ore and a/ter the o0erator2
UMy$3mber F &,,B
> ternary o0erator re?3ires three o0erands2
UTal3e& F &,B
UTal3eC F J&,JB
(UTal3e& FF UTal3eC) 6 Ues3lt F Jtr3eJ ( Ues3lt F J/alseJB
>rithmetic A0erators
>rithmetic o0erators are 3sed in PHP to 0er/orm mathematical calc3lations2
>rithmetic #inary A0erators
Symbol A0eration Descri0tion
Y >ddition >dds two o0erands
% S3btraction S3btracts the right o0erand
/rom the le/t o0erand
S M3lti0lication M3lti0lies two o0erands
1 Di8ision Di8ides the le/t o0erand by
the right o0erand
L Mod3l3s Di8ides the le/t o0erand by
the right o0erand and
ret3rns the remainder
PHP >rithmetic binary o0erators
Mcha0terG,&G,V20h0N
D60h0
11 >DD"9"A$
U7 F &,,B
Uy F C,,B
Uet3rnTal3e F U7 Y UyB
echo JD0Eet3rnTal3e a/ter addition e70ression( J, Uet3rnTal3e, JD10EJB
11 SK#9>49"A$
U7 F &,B
Uy F *B
Uet3rnTal3e F U7 % UyB
echo JD0Eet3rnTal3e a/ter s3btraction e70ression( J, Uet3rnTal3e, JD10EJB
11 MKL9"PL"4>9"A$
U7 F CB
Uy F VB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e a/ter m3lti0lication e70ression( J, Uet3rnTal3e, JD10EJB
11 D"T"S"A$
U7 F C.B
Uy F 'B
Uet3rnTal3e F U7 1 UyB
echo JD0Eet3rnTal3e a/ter di8ision e70ression( J, Uet3rnTal3e, JD10EJB
11 MADKLKS
U7 F 'B
Uy F CB
Uet3rnTal3e F U7 L UyB
echo JD0Eet3rnTal3e a/ter mod3l3s e70ression( J, Uet3rnTal3e, JD10EJB
11 4on8ert string to n3mbers
U7 F JCJB
Uy F J'JB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e a/ter being con8erted to n3mber and 0er/orm m3lit0lication
e70ression( J, Uet3rnTal3e, JD10EJB
11 4on8ert string to n3mber, one is not a n3mber
U7 F JCJB
Uy F Jabc'JB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e with one non n3mber string and 0er/orm m3lit0lication
e70ression( J, Uet3rnTal3e, JD10EJB
6E
>rithmetic Knary A0erators
Symbol A0eration Descri0tion
YY "ncrement "ncreases an o0erand by a
8al3e o/ &
%% Decrement Decreases an o0erand by a
8al3e o/ &
PHP >rithmetic 3nary o0erators
9he increment (YY) and decrement (%%) 3nary o0erators can be 3sed as 0re/i7 or 0ost/i7
o0erators2
> 0re/i7 o0erator is 0laced be/ore a 8ariable2
> 0ost/i7 o0erator is 0laced a/ter a 8ariable2
Mcha0terG,&G,*20h0N
D60h0
11 Pre/i7 increment
U7 F VB
Uy F ,B
echo JD0ETal3e o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
Uy F YYU7B
echo JD0Ees3lt a/ter Pre/i7 increment o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Post/i7 increment
Uy F U7YYB
echo JD0Ees3lt a/ter Post/i7 increment o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Pre/i7 decrement
Uy F %%U7B
echo JD0Ees3lt a/ter Pre/i7 decrement o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Post/i7 decrement
Uy F U7%%B
echo JD0Ees3lt a/ter Post/i7 decrement o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
6E
>ssignment A0erators
>ssignment o0erators are 3sed /or assigning a 8al3e to a 8ariable2
PHP incl3des additional assignment o0erators called com0o3nd assignment o0erators,
which 0er/orm mathematical calc3lations on 8ariables and literal 8al3es in an e70ression
and then assign a new 8al3e to the le/t o0erand2
Symbol A0eration Descri0tion
F >ssignment >ssigns the 8al3e o/ the
right o0erand to the le/t
o0erand
YF 4om0o3nd addition
assignment
>dds the 8al3e o/ the right
o0erand to the 8al3e o/ the
le/t o0erand and assigns the
new 8al3e to the le/t
o0erand
%F 4om0o3nd s3btraction
assignment
S3btract the 8al3e o/ the
right o0erand /rom the 8al3e
o/ the le/t o0erand and
assigns the new 8al3e to the
le/t o0erand
SF 4om0o3nd m3lti0lication
assignment
M3lti0lies the 8al3e o/ the
right o0erand by the 8al3e
o/ the le/t o0erand and
assigns the new 8al3e to the
le/t o0erand
1F 4om0o3nd di8ision
assignment
Di8ides the 8al3e o/ the le/t
o0erand by the 8al3e o/ the
right o0erand and assigns
the new 8al3e to the le/t
o0erand
LF 4om0o3nd mod3l3s
assignment
Di8ides the 8al3e o/ the le/t
o0erand by the 8al3e o/ the
right o0erand and assigns
the remainder (mod3l3s) to
the le/t o0erand
Mcha0terG,&G,+20h0N
D60h0
11 >ssignment and com0o3nd addition assignment
echo JD0EJB
U7 F &,,B
Uy F C,,B
U7 YF UyB
echo U7, JDbr 1EJB

11 4om0o3nd s3btraction assignment
U7 F &,B
Uy F *B
U7 %F UyB
echo U7, JDbr 1EJB
11 4om0o3nd m3lti0lication assignment
U7 F CB
Uy F VB
U7 SF UyB
echo U7, JDbr 1EJB
11 4om0o3nd di8ision assignment
U7 F C.B
Uy F 'B
U7 1F UyB
echo U7, JDbr 1EJB
11 4om0o3nd mod3l3s assignment
U7 F 'B
Uy F CB
U7 LF UyB
echo U7, JD10EJB
6E
4om0arison and 4onditional A0erators
4om0arison o0erators are 3sed to determine how one o0erand com0ares to another2 >
#oolean 8al3e o/ 9K!1tr3e or <>LS!1/alse is ret3rned2
Symbol A0eration Descri0tion
FF !?3al et3rns 9K! i/ the o0erands are
e?3al
E Greater than et3rns 9K! i/ the le/t o0erand is
greater than the right o0erand
EF Greater than or
e?3al to
et3rns 9K! i/ the le/t o0erand is
greater than or e?3al to the right
o0erand
D Less than et3rns 9K! i/ the le/t o0erand is
less than the right o0erand
DF Less than or e?3al
to
et3rns 9K! i/ the le/t o0erand is
less than or e?3al to the right
o0erand
\F or DE $ot e?3al et3rns 9K! i/ the o0erands are
not e?3al
FFF Strict e?3al et3rns 9K! i/ the o0erands are
e?3al and o/ the same data ty0e
\FF Strict not e?3al et3rns 9K! i/ the o0erands are
not e?3al or not o/ the same data
ty0e
9he com0arison o0erator is o/ten 3sed with the conditional o0erator2 9he conditional
o0erator e7ec3tes one o/ two e70ressions, based on the res3lts o/ a conditional
e70ression2
UTal3e& F &,B
UTal3eC F J&,JB
Ues3lt F (UTal3e& FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
Mcha0terG,&G,)20h0N
D60h0
UTal3e& F J/irst te7t stringJB
UTal3eC F Jsecond te7t stringJB
Uet3rnTal3e F (UTal3e& FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
echo OUTal3e& e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1ED10EJB
UTal3e& F -,B
UTal3eC F *-B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \F UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& DE UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& DE not e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& E UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& greater than UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& EF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& greater than e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& D UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& less than UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& DF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& less than or e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1ED10EJB
UTal3e& F C-B
UTal3eC F C-B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FFF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& strictly e?3al to UTal3eC and the same data ty0e( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not strictly e?3al to UTal3eC or not the same data ty0e( O, Uet3rnTal3e,
JDbr 1ED10EJB
UTal3e& F &,B
UTal3eC F J&,JB
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FFF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& strictly e?3al to UTal3eC and the same data ty0e( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not strictly e?3al to UTal3eC or not the same data ty0e( O, Uet3rnTal3e,
JDbr 1EJB
echo JD10EJB
6E
Logical A0erators
Logical o0erators are 3sed /or com0aring two #oolean o0erands /or e?3ality2
#oolean o0erands are o0erands that are limited to the 8al3es 9K! or <>LS!2
Symbol A0eration Descri0tion
]] or >$D Logical >nd et3rns 9K! i/ both the
le/t o0erand and right
o0erand ret3rn a 8al3e o/
9K!B otherwise, it ret3rns
a 8al3e o/ <>LS!
^^ or A Logical Ar et3rns 9K! i/ either the
le/t o0erand or right
o0erand ret3rns a 8al3e o/
9K!B otherwise (neither
o0erand ret3rns a 8al3e o/
9K!), it ret3rns a 8al3e o/
<>LS!
:A Logical !7cl3si8e Ar et3rns 9K! i/ only one
o/ the le/t o0erand or right
o0erand ret3rns a 8al3e o/
9K!B otherwise (neither
o0erand ret3rns a 8al3e o/
9K! or both o0erands
ret3rn a 8al3e o/ 9K!), it
ret3rns a 8al3e o/ <>LS!
\ Logical $ot et3rns 9K! i/ an
e70ression is <>LS! and
ret3rns <>LS! i/ an
e70ression is 9K!
<or the logical Ar o0erator, yo3 can 3se either ^^ or A2 <or the logical >nd o0erator, yo3
can 3se either ]] or >$D2 (#e care/3l on the o0erator 0recedence2 ]] ^^ ha8e higher
0recedence than >$D A, see e7am0les)
Logical o0erators are o/ten 3sed with com0arison o0erators to e8al3ate e70ressions,
allowing yo3 to combine the res3lts o/ se8eral e70ressions into a single statement2
$A9!( 9he logical !7cl3si8e Ar (:A) o0erator, which ret3rns 9K! i/ only one o/ the
o0erands is 9K!, b3t not both2
Mcha0terG,&G&,20h0N
D60h0
11 >nd o0erator (]] >$D and)
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ ]] U>ge DF C&B 11 ret3rns <>LS!
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ >$D U>ge DF C&B 11 isk<actor gets assigned to tr3e
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ and U>ge DF C&B 11 isk<actor gets assigned to tr3e
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
Uisk<actor F (UGender FF JmaleJ and U>ge DF C&)B 11 3se () to /i7 the 0roblem
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
11 A o0erator (^^ A or)
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& ^^ US0eeding9icket E ,B 11 ret3rns 9K!
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& A US0eeding9icket E ,B 11 isk<actor gets assigned to /alse
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& or US0eeding9icket E ,B 11 isk<actor gets assigned to /alse
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F (U>ge DF C& or US0eeding9icket E ,)B 11 3se () to /i7 the 0roblem
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
6E
9y0e 4asting
!8en tho3gh PHP a3tomatically assigns the data ty0e o/ a 8ariable, yo3 can ens3re a
8ariable o/ a 0artic3lar data ty0e by 3sing casting or ty0e casting2
U$ewTariable F (newGty0e) UAldTariableB
$A9!( casting does not change the data ty0e o/ the original 8ariable2 ather, casting
co0ies the data /rom the old 8ariable, con8erts it to the data ty0e s0eci/ied by the ty0e%
casting o0erator, and then assign the 8al3e to the new 8ariable2
$A9!( PHP can con8ert a string to a n3meric 8al3e i/ the string starts with a n3meric
8al3e2 >ny s3bse?3ent non%n3meric characters are ignored2
UData& F J&C' abcJB
UDataC F (int) UData&B 11 DataC will get int &C' only2
;o3 can 8iew a 8ariable@s ty0e by 3sing the getty0e() /3nction which will ret3rns one o/
the /ollowing strings(
(#oolean, "nteger, Do3ble, String, >rray, AbXect, eso3rce, $KLL, Knknown ty0e)
9he best way is to 3se one o/ the &- isGS() /3nctions that test /or 8ario3s kinds o/ data
ty0es2 (htt0(11www20h02net1man3al1en1book28ar20h0)
(isGn3meric(), isGstring(), isGint(), isGdo3ble())
Mcha0terG,&G&&20h0N
D60h0
U$3mString F JC' milesJB
Ues3lt F U$3mString S CB
echo JD0EArignal data ( U$3mString, es3lt ( Ues3ltD10EJB
UString$3m F Jan C' milesJB
Ues3lt F UString$3m S CB
echo JD0EArignal data ( UString$3m, es3lt ( Ues3ltD10EJB
UData F VCB
echo JD0EAriginal data( UDataDbr 1EJB
echo getty0e(UData), JDbr 1EJB
echo J4asting do3ble( J, getty0e((do3ble)UData), JDbr 1EJB
echo J4asting string( J, getty0e((string)UData), JDbr 1EJB
echo J4asting boolean( J, getty0e((boolean)UData), JDbr 1EJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ VC is( Ues3ltDbr 1EJB
UData F ,B
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ , is( Ues3ltDbr 1EJB
UData F %CB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ %C is( Ues3ltDbr 1EJB
UData F JAneJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ non em0ty string is( Ues3ltDbr 1EJB
UData F JJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ em0ty string is( Ues3ltDbr 1EJB
UData F $KLLB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ $KLL or n3ll is( Ues3ltDbr 1EJB
Ues3lt F (isGn3ll(UData))6 J9r3eJ ( J<alseJB
echo JisGn3ll($KLL) /3nction( Ues3ltDbr 1EJB
UData F '2&.&VB
Ues3lt F (isGn3meric(UData))6 J9r3eJ ( J<alseJB
echo JisGn3meric(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isG/loat(UData))6 J9r3eJ ( J<alseJB
echo JisG/loat(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGdo3ble(UData))6 J9r3eJ ( J<alseJB
echo JisGdo3ble(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGstring(UData))6 J9r3eJ ( J<alseJB
echo JisGstring(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGobXect(UData))6 J9r3eJ ( J<alseJB
echo JisGobXect(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGarray(UData))6 J9r3eJ ( J<alseJB
echo JisGarray(UData) is( Ues3ltDbr 1EJB
UData F (int) UDataB
Ues3lt F (isGint(UData))6 J9r3eJ ( J<alseJB
echo JisGint(UData) o/ UData is( Ues3ltDbr 1EJB
UData F tr3eB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) is( Ues3ltDbr 1EJB
UData F /alseB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) o/ /alse is( Ues3ltDbr 1EJB
UData F JMy String DataJB
Ues3lt F (isGstring(UData))6 J9r3eJ ( J<alseJB
echo JisGstring(UData) is( Ues3ltDbr 1EJB
11 A0erator 0recedence
U7 F 'B
Uy F CB
echo JAriginal 7 and y( U7 UyDbr 1EJB
U7 F Uy SF YYU7B
echo J>/ter e70ression 7 and y( U7 UyJB
echo JD10EJB
6E
Knderstanding A0erator Precedence
A0erator 0recedence re/ers to the order in which o0erations in an e70ression are
e8al3ated2
5hen 0er/orming o0erations with o0erators in the same 0recedence gro30, the order o/
0recedence is determined by the o0erators@ associati8ity2 >ssociati8ity is e8al3ated on a
le/t%to%right or a right%to%le/t basis2
Symbol A0erator >ssociati8ity
new clone $ew AbXect%highest 0recedence $one
MN >rray elements ight to le/t
YY %% "ncrement1decrement ight to le/t
(int) (do3ble) (string)
(array) (obXect)
4ast ight to le/t
_ S300ress errors ight to le/t
instanceo/ 9y0es $one
\ Logical not ight to le/t
S 1 L M3lti0lication1di8ision1mod3l3s Le/t to right
Y % 2 >ddition1s3btraction1string
concatenation
Le/t to right
D DF E EF DE 4om0arison $one
FF \F FFF \FF !?3ality $one
]] Logical >nd Le/t to right
^^ Logical Ar Le/t to right
6( 4onditional o0erator Le/t to right
F YF %F SF 1F LF 2F >ssignment statements ight to le/t
>$D Logical >nd Le/t to right
:A Logical !7cl3si8e Ar Le/t to right
A Logical Ar Le/t to right
, List se0arator Le/t to right
e/erence( htt0(11www20h02net1man3al1en1lang3age2o0erators20recedence20h0
Sam0le Programs(
Mcha0terG,&G,&20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,&
>3thor( Hans ;i0
Date( +1C+1C,&,
%%E
DtitleEPHP 4ha0ter ,&D1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % /o3r ty0es o/ code declaration blocksD1h&E
D0E
D60h0
echo J9his te7t is 0rinted 3sing standard PHP scri0t delimiters2JB
6E
D10E
D0E
Dscri0t lang3ageFJ0h0JE
echo J9his te7t is 0rinted 3sing a PHP scri0t section2JB
D1scri0tE
D10E
D0E
D6
echo J9his te7t is 0rinted 3sing short PHP scri0t delimiters2JB
6E
D10E
D0E
DL
echo J9his te7t is 0rinted 3sing >SP%style scri0t delimiters2JB
LE
D10E
D1bodyE
D1htmlE
Mcha0terG,&G,C20h0N
D60h0 0h0in/o()B 6E
Mcha0terG,&G,'20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& "nteger <loating%Point
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % "nteger ] <loating%PointD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % $3meric Data 9y0esD1h&E
D60h0
U"ntegerTar F &-,B
U<loatingPointTar F '2,!*B 11/loating%0oint
echo JD0E"nteger Tariable( U"ntegerTarDbr 1EJB
echo J<loating%0oint 8ariable( U<loatingPointTarD10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,.20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& #oolean Tal3es
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % #oolean Tal3esD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % #oolean Tal3esD1h&E
D60h0
Ue0eat43stomer F tr3eB 11 or 9K!
echo JD0Ee0eat 43stomer( Ue0eat43stomerD10EJB
U$3mG0ositi8e F C,B
i/ (U$3mG0ositi8e) Z
echo JD0E$3m 0ositi8e( U$3mG0ositi8eD10EJB
[
U$3mGnegati8e F %C,B
i/ (U$3mGnegati8e) Z
echo JD0E$3m negati8e( U$3mGnegati8eD10EJB
[ else Z
echo JD0E$3mGnegati8e is a <>LS! condition( U$3mGnegati8e D10EJB
[
U$3mGPero F ,B
i/ (U$3mGPero) Z
echo JD0E$3m Pero( U$3mGPeroD10EJB
[ else Z
echo JD0E$3mGPero is a <>LS! condition( U$3mGPero D10EJB
[
Ue0eatG0l3s& F Ue0eat43stomer Y &B
echo JD0Ee0eat 0l3s&( Ue0eatG0l3s&D10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,-20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& >rray
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % >rrayD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % >rrayD1h&E
D60h0
UMy>rray F array(Jdata,J, Jdata&J, JdataCJ)B
UHoteleser8ation F array(
JMy $ameJ, 11 g3est name (string)
C, 11 R o/ nights (integer)
+)2)-, 11 0rice 0er night (/loating%0oint)
tr3e)B 11 nonsmoking room (#oolean)
UMy>rrayMN F Jdata'JB
UMy>rrayMN F Jdata.JB
UMy>rrayMN F Jdata-JB
1S to /ind the total n3mber o/ elements in an array, 3se the co3nt() /3nction2 S1
echo JD0E$3mber o/ elements in My>rray J, co3nt(UMy>rray), JDbr 1EJ,
J$3mber o/ elements in Hoteleser8ation array J, co3nt(UHoteleser8ation), JD10EJB
echo JD0E9here are J, co3nt(UMy>rray), J elements in My>rray2D1PED0EJB
echo JUMy>rrayM,NDbr 1EJB
echo JUMy>rrayM&NDbr 1EJB
echo JUMy>rrayMCNDbr 1EJB
echo JUMy>rrayM'NDbr 1EJB
echo JUMy>rrayM.NDbr 1EJB
echo JUMy>rrayM-ND10EJB
1S Modi/ying elements S1
UMy>rrayMCN F JMore dataJB
UMy>rrayM&N F JLess dataJB
1S 3se 0rintGr(), 8arGe70ort(), and 8arGd3m0() /3nctions S1
echo JD0ED0reEJB
0rintGr(UMy>rray)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy>rray)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy>rray)B
echo JD10reED10EJB
1S 3se 0rintGr(), 8arGe70ort(), and 8arGd3m0() /3nctions in 8ariableS1
UMyData F JHelloJB
echo JD0ED0reEJB
0rintGr(UMyData)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMyData)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMyData)B
echo JD10reED10EJB
UMy$3m F ',B
echo JD0ED0reEJB
0rintGr(UMy$3m)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy$3m)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy$3m)B
echo JD10reED10EJB
UMy#oolean9r3e F tr3eB
echo JD0ED0reEJB
0rintGr(UMy#oolean9r3e)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy#oolean9r3e)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy#oolean9r3e)B
echo JD10reED10EJB
UMy#oolean<alse F /alseB
echo JD0ED0reEJB
0rintGr(UMy#oolean<alse)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGe70ort(UMy#oolean<alse)B
echo JD10reED10EJB
echo JD0ED0reEJB
8arGd3m0(UMy#oolean<alse)B
echo JD10reED10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,V20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& >rithmetic #inary A0erators
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % >rithmetic #inary A0eratorsD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % >rithmetic #inary A0eratorsD1h&E
D60h0
11 >DD"9"A$
U7 F &,,B
Uy F C,,B
Uet3rnTal3e F U7 Y UyB
echo JD0Eet3rnTal3e a/ter addition e70ression( J, Uet3rnTal3e, JD10EJB
11 SK#9>49"A$
U7 F &,B
Uy F *B
Uet3rnTal3e F U7 % UyB
echo JD0Eet3rnTal3e a/ter s3btraction e70ression( J, Uet3rnTal3e, JD10EJB
11 MKL9"PL"4>9"A$
U7 F CB
Uy F VB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e a/ter m3lti0lication e70ression( J, Uet3rnTal3e, JD10EJB
11 D"T"S"A$
U7 F C.B
Uy F 'B
Uet3rnTal3e F U7 1 UyB
echo JD0Eet3rnTal3e a/ter di8ision e70ression( J, Uet3rnTal3e, JD10EJB
11 MADKLKS
U7 F 'B
Uy F CB
Uet3rnTal3e F U7 L UyB
echo JD0Eet3rnTal3e a/ter mod3l3s e70ression( J, Uet3rnTal3e, JD10EJB
11 4on8ert string to n3mbers
U7 F JCJB
Uy F J'JB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e a/ter being con8erted to n3mber and 0er/orm m3lit0lication
e70ression( J, Uet3rnTal3e, JD10EJB
11 4on8ert string to n3mber, one is not a n3mber
U7 F JCJB
Uy F Jabc'JB
Uet3rnTal3e F U7 S UyB
echo JD0Eet3rnTal3e with one non n3mber string and 0er/orm m3lit0lication
e70ression( J, Uet3rnTal3e, JD10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,*20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& >rithmetic Knary A0erators
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % >rithmetic Knary A0eratorsD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % >rithmetic Knary A0eratorsD1h&E
D60h0
11 Pre/i7 increment
U7 F VB
Uy F ,B
echo JD0ETal3e o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
Uy F YYU7B
echo JD0Ees3lt a/ter Pre/i7 increment o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Post/i7 increment
Uy F U7YYB
echo JD0Ees3lt a/ter Post/i7 increment o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Pre/i7 decrement
Uy F %%U7B
echo JD0Ees3lt a/ter Pre/i7 decrement o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
11 Post/i7 decrement
Uy F U7%%B
echo JD0Ees3lt a/ter Post/i7 decrement o/ 7( J, U7, J Tal3e o/ y( J, Uy, JD10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,+20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& >rithmetic >ssignment A0erators
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % >rithmetic >ssignment A0eratorsD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % >rithmetic >ssignment A0eratorsD1h&E
D60h0
11 >ssignment and com0o3nd addition assignment
echo JD0EJB
U7 F &,,B
Uy F C,,B
U7 YF UyB
echo U7, JDbr 1EJB

11 4om0o3nd s3btraction assignment
U7 F &,B
Uy F *B
U7 %F UyB
echo U7, JDbr 1EJB
11 4om0o3nd m3lti0lication assignment
U7 F CB
Uy F VB
U7 SF UyB
echo U7, JDbr 1EJB
11 4om0o3nd di8ision assignment
U7 F C.B
Uy F 'B
U7 1F UyB
echo U7, JDbr 1EJB
11 4om0o3nd mod3l3s assignment
U7 F 'B
Uy F CB
U7 LF UyB
echo U7, JD10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G,)20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& 4om0arison and 4onditional A0erators
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % 4om0arison and 4onditional A0eratorsD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % 4om0arison and 4onditional A0eratorsD1h&E
D60h0
UTal3e& F J/irst te7t stringJB
UTal3eC F Jsecond te7t stringJB
Uet3rnTal3e F (UTal3e& FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
echo OUTal3e& e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1ED10EJB
UTal3e& F -,B
UTal3eC F *-B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \F UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& DE UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& DE not e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& E UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& greater than UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& EF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& greater than e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& D UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& less than UTal3eC( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& DF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& less than or e?3al to UTal3eC( O, Uet3rnTal3e, JDbr 1ED10EJB
UTal3e& F C-B
UTal3eC F C-B
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FFF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& strictly e?3al to UTal3eC and the same data ty0e( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not strictly e?3al to UTal3eC or not the same data ty0e( O, Uet3rnTal3e,
JDbr 1ED10EJB
UTal3e& F &,B
UTal3eC F J&,JB
echo JD0EJB
echo JTal3e& F UTal3e&, Tal3eC F UTal3eC Dbr 1EDbr 1EJB
Uet3rnTal3e F (UTal3e& FFF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& strictly e?3al to UTal3eC and the same data ty0e( O, Uet3rnTal3e, JDbr 1EJB
Uet3rnTal3e F (UTal3e& \FF UTal3eC 6 Jtr3eJ ( J/alseJ)B
echo OUTal3e& not strictly e?3al to UTal3eC or not the same data ty0e( O, Uet3rnTal3e,
JDbr 1EJB
echo JD10EJB
6E
D1bodyE
D1htmlE
Mcha0terG,&G&,20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& Logical A0erators
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % Logical A0eratorsD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % Logical A0eratorsD1h&E
D60h0
11 >nd o0erator (]] >$D and)
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ ]] U>ge DF C&B 11 ret3rns <>LS!
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ >$D U>ge DF C&B 11 isk<actor gets assigned to tr3e
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
UGender F JmaleJB
U>ge F C+B
Uisk<actor F UGender FF JmaleJ and U>ge DF C&B 11 isk<actor gets assigned to tr3e
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
Uisk<actor F (UGender FF JmaleJ and U>ge DF C&)B 11 3se () to /i7 the 0roblem
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
11 A o0erator (^^ A or)
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& ^^ US0eeding9icket E ,B 11 ret3rns 9K!
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& A US0eeding9icket E ,B 11 isk<actor gets assigned to /alse
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F U>ge DF C& or US0eeding9icket E ,B 11 isk<actor gets assigned to /alse
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
US0eeding9icket F CB
U>ge F C+B
Uisk<actor F (U>ge DF C& or US0eeding9icket E ,)B 11 3se () to /i7 the 0roblem
i/ (Uisk<actor) Z
echo JD0Eisk<actor is 9K!( Uisk<actorD10EJB
[ else Z
echo JD0Eisk<actor is <>LS!( Uisk<actorD10EJB
[
6E
D1bodyE
D1htmlE
Mcha0terG,&G&&20h0N
D\DA49;P! html PK#L"4 J%115'411D9D :H9ML &2, 9ransitional11!$J
Jhtt0(11www2w'2org1917html&1D9D17html&%transitional2dtdJE
Dhtml 7mlnsFJhtt0(11www2w'2org1&)))17htmlJE
DheadE
D\%% PHP cha0ter ,& 9y0e 4asting
>3thor( Hans ;i0
Date( &,1C1C,&,
%%E
DtitleEPHP 4ha0ter ,& % 9y0e 4astingD1titleE
D1headE
DbodyE
Dh&E4ha0ter ,& % 9y0e 4astingD1h&E
D60h0
U$3mString F JC' milesJB
Ues3lt F U$3mString S CB
echo JD0EArignal data ( U$3mString, es3lt ( Ues3ltD10EJB
UString$3m F Jan C' milesJB
Ues3lt F UString$3m S CB
echo JD0EArignal data ( UString$3m, es3lt ( Ues3ltD10EJB
UData F VCB
echo JD0EAriginal data( UDataDbr 1EJB
echo getty0e(UData), JDbr 1EJB
echo J4asting do3ble( J, getty0e((do3ble)UData), JDbr 1EJB
echo J4asting string( J, getty0e((string)UData), JDbr 1EJB
echo J4asting boolean( J, getty0e((boolean)UData), JDbr 1EJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ VC is( Ues3ltDbr 1EJB
UData F ,B
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ , is( Ues3ltDbr 1EJB
UData F %CB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ %C is( Ues3ltDbr 1EJB
UData F JAneJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ non em0ty string is( Ues3ltDbr 1EJB
UData F JJB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ em0ty string is( Ues3ltDbr 1EJB
UData F $KLLB
Ues3lt F ((boolean) UData)6 J9r3eJ ( J<alseJB
echo J#oolean o/ $KLL or n3ll is( Ues3ltDbr 1EJB
Ues3lt F (isGn3ll(UData))6 J9r3eJ ( J<alseJB
echo JisGn3ll($KLL) /3nction( Ues3ltDbr 1EJB
UData F '2&.&VB
Ues3lt F (isGn3meric(UData))6 J9r3eJ ( J<alseJB
echo JisGn3meric(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isG/loat(UData))6 J9r3eJ ( J<alseJB
echo JisG/loat(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGdo3ble(UData))6 J9r3eJ ( J<alseJB
echo JisGdo3ble(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGstring(UData))6 J9r3eJ ( J<alseJB
echo JisGstring(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGobXect(UData))6 J9r3eJ ( J<alseJB
echo JisGobXect(UData) is( Ues3ltDbr 1EJB
Ues3lt F (isGarray(UData))6 J9r3eJ ( J<alseJB
echo JisGarray(UData) is( Ues3ltDbr 1EJB
UData F (int) UDataB
Ues3lt F (isGint(UData))6 J9r3eJ ( J<alseJB
echo JisGint(UData) o/ UData is( Ues3ltDbr 1EJB
UData F tr3eB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) is( Ues3ltDbr 1EJB
UData F /alseB
Ues3lt F (isGbool(UData))6 J9r3eJ ( J<alseJB
echo JisGbool(UData) o/ /alse is( Ues3ltDbr 1EJB
UData F JMy String DataJB
Ues3lt F (isGstring(UData))6 J9r3eJ ( J<alseJB
echo JisGstring(UData) is( Ues3ltDbr 1EJB
11 A0erator 0recedence
U7 F 'B
Uy F CB
echo JAriginal 7 and y( U7 UyDbr 1EJB
U7 F Uy SF YYU7B
echo J>/ter e70ression 7 and y( U7 UyJB
echo JD10EJB
6E
D1bodyE
D1htmlE

Você também pode gostar