Some output statements:
$name = john
\$name = $name
\n$count = 4
You don't need interpolation; you can always use concatenation or multiple args instead:
$name = john
$name = john
We can also interpolate array-lookups with numeric indices:
$crsarr[7] = 99
Beware interpolating arrays lookups with string-indices:
crsarr[webII] = 325
crsarr[$class] = 325
Instead, use concatenation or multiple args:
$crsarr["webII"] = 325
$crsarr["webII"] = 325
(Okay, you can also use curly-brackets, ech:)
crsarr['webII'] = 325
$crsarr[$crs] = 325
The constant COURSE holds ITEC 325
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'stderr');
ini_set('display_startup_errors', true);
?>
<html>
<!-- simple.php -->
<head>
</head>
<body>
<p>
<?php
# Assign some variables
$name = "john";
$count = 4;
echo "Some output statements: <br/> \n";
echo "\$name = $name <br /> \n";
echo '\$name = $name <br /> \n';
echo "\$count = $count <br /> \n";
echo "\n\n";
echo "You don't <em>need</em> interpolation; ";
echo "you can always use concatenation or multiple args instead: <br /> \n";
echo "\$name = ", $name, "<br /> \n";
echo "\$name = " . $name . "<br /> \n";
echo "\n\n";
echo "We can also interpolate array-lookups with numeric indices:<br/>\n";
$crsarr = array( "webII"=>325, "java1"=>120, 7 => 99 );
echo "\$crsarr[7] = $crsarr[7]", "<br/>\n";
echo "<br/>\n";
echo "Beware interpolating arrays lookups with string-indices:<br/>\n";
#echo "crsarr['webII'] = $crsarr['webII']<br />\n";
echo "crsarr[webII] = $crsarr[webII]<br />\n";
$class = "webII";
echo "crsarr[\$class] = $crsarr[$class]<br />\n";
echo "Instead, use concatenation or multiple args:<br />\n";
echo "\$crsarr[\"webII\"] = " . $crsarr["webII"] . "\n<br />";
echo "\$crsarr[\"webII\"] = ", $crsarr["webII"], "\n<br />";
echo "(Okay, you can also use curly-brackets, ech:)<br />\n";
echo "crsarr['webII'] = ${crsarr['webII']}<br />\n";
$crs = 'webII';
echo "\$crsarr[\$crs] = $crsarr[$crs]<br />\n";
define ("COURSE","ITEC 325");
print( "The constant COURSE holds " . COURSE . "\n <br />" );
?>
</p>
<h2>Source Code</h2>
<p>
<?php
highlight_file('php-ch02-simple.php');
?>
</p>
</body>
</html>