1.2 Introduction To PHP - PHP Keywords
1.2 Introduction To PHP - PHP Keywords
Introduction to PHP
Dr. Charles Severance
www.wa4e.com
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
Keywords
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
Keywords
abstract and array() as break case catch class clone
const continue declare default do else elseif end
declare endfor endforeach endif endswitch endwhile
extends final for foreach function global goto if
implements interface instanceof namespace new or
private protected public static switch $this throw try
use var while xor
http://php.net/manual/en/reserved.php
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
Variable Names
• Start with a dollar sign ($) followed by a letter or underscore,
followed by any number of letters, numbers, or underscores
• Case matters
$abc = 12; abc = 12;
$total = 0; $2php = 0;
$largest_so_far = 0; $bad-punc = 0;
http://php.net/manual/en/language.variables.basics.php
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
$x = 2; $x = 2;
$y = x + 5; y = $x + 5;
print $y; print $x;
5 Parse error
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
$x = 5;
$y = array("x" => "Hello");
print $y[x];
Hello
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
http://php.net/manual/en/language.types.string.php
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
<?php
echo "this is a simple string\n"; Double Quote
echo "You can also have embedded newlines in
strings this way as it is
okay to do";
// Outputs: Variables do 12
$expand = 12;
echo "Variables do $expand\n";
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
<?php
echo 'this is a simple string'; Single Quote
Comments in PHP J
echo 'This is a test'; // This is a c++ style comment
/* This is a multi line comment
yet another line of comment */
echo 'This is yet another test';
echo 'One Final Test'; # This is a shell-style comment
http://php.net/manual/en/language.basic-syntax.comments.php
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
Output
• echo is a language construct - can <?php
be treated like a function with $x = "15" + 27;
one parameter. Without echo $x;
parentheses, it accepts multiple echo("\n");
echo $x, "\n";
parameters.
print $x;
• print is a function - only one print "\n";
print($x);
parameter, but parentheses are
print("\n");
optional so it can look like a ?>
language construct.
WEB APPLICATIONS
Introduction to PHP FOR EVERYBODY
Acknowledgements / Contributions
These slides are Copyright 2010- Charles R. Severance Continue new Contributors and Translators here
(www.dr-chuck.com) as part of www.wa4e.com and made
available under a Creative Commons Attribution 4.0 License.
Please maintain this last slide in all copies of the document
to comply with the attribution requirements of the license. If
you make a change, feel free to add your name and
organization to the list of contributors on this page as you
republish the materials.