HTML and CSS Reference
In-Depth Information
you can change it to any other data type or expressions such as,
$userName = 55 ;
$userName = true ;
$userName =( 15 * 3 );
Weakly typed languages have certain advantages and disadvantages, but they tend to be easier
to learn initially.
Variables
As mentioned earlier in this chapter, all variable labels begin with a dollar sign ( $ ). h ey can
be placed in other strings and recognized regardless of data type. Try out the following
( variableInString.php in this chapter's folder at www.wiley.com/go/
smashinghtml5 ):
<?php
$ram = “dynamic random access memory” ;
$speed = ”much GHz in” ;
$money = 2 ;
$truism = ”You can't have too much $ram or too $speed a processor. (That will be
$money cents for the advice.)” ;
print $truism ;
?>
333
When you test that code, you'll see the following output:
You can't have too much dynamic random access memory or too much GHz in a processor.
(That will be 2 cents for the advice.)
In most other languages, you would have to use concatenation.
Constants
Constants are like variables in PHP except they do not change in value. h ey're assigned
values in a much dif erent way than variables are, and they're case-sensitive. By convention
(and good practice), they're in all caps ( LIKE_THIS ). h e basic assignment format is:
define ( “CONSTANT_NAME” , “value” );
Try the following little script ( constants.php in this chapter's folder at www.wiley.
com/go/smashinghtml5 ), to get an idea of how they work:
<?php
define ( “FRED” , “Fred J. Jones “ );
define ( “MONEY” , 200 );
define ( “BUCKS” , “$” );
echo FRED , “ donated “ , BUCKS , MONEY , “ to charity.” ;
?>
 
Search WWH ::




Custom Search