What I learned in my PHP bootcamp
Last year I did a coding bootcamp at BAVC. As a non-coder , I’m planning to share what I learned here. Maybe it’ll be useful or inspiring for you. This time I’m talking about PHP.
PHP originally stood for Personal Home Page, but it now stands for the recursive acronym PHP — Hypertext Preprocessor. PHP is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
What does it mean?
<title>PHP is cool</title>
<?php echo '<p>Hello Medium</p>'; ?>
A majority of sites on the web right now run on PHP. Due in large part to its popularity as the language of choice for back-end of content management systems — CMS, like WordPress, Drupal, and Joomla.
A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value.
Note: Function names are case-insensitive.
echo " and welcome to my Blog!" ;
echo "Today is Sunday August 28th, 2017. <br />";
An array is a special variable which can hold more than one value at a time. An ordered map that is a type that associates values to keys. In PHP, there are three types of arrays:
- Indexed arrays — Arrays with numeric index
- Associative arrays — Arrays with named keys
- Multidimensional arrays — Arrays containing one or more arrays
/* $name1 = "Madonna";
$name2 = "Kathleen Hanna";
$name3 = "Edith Piaf";
$name4 = "Nina Simone";
$name5 = "Madeleine Peyroux";
$artists = array( "Madonna", "Kathleen Hanna", "Edith Piaf", "Nina Simone", "Madeleine Peyroux" );
// echo $artists[ 3 ] . "is the singer for Le Tigre";
for( $i = 0; $i < sizeof($artists); $i++ )
echo "Current Artist: " . $artists[ $i ];
echo "<br />";
The “if else” statement executes some code if a condition is true and another code if that condition is false.
$myAge = 65;
if( $myAge >= 21 )
echo "Welcome to the show! <br />";
if( $myAge >=60 )
echo "You get a senior discount ticket!";
else if( $myAge >= 13 )
echo "You can come in but must stay in the teen area.";
echo "Sorry, you are too young.<br />";
echo "Come back in a few years.";
Process form is the possibility to respond to user queries or data submitted from HTML forms. You can process information gathered by an HTML form and use PHP code to make decisions based off this information to create dynamic web pages.
echo "Hello, " . $_GET[ "firstName"];
echo "The age entered was " . $_GET[ "age"];
echo "Favorite color is " . $_GET[ "favoriteColor"];
The switch-case statement tests a variable against a series of values until it finds a match and then executes the block of code corresponding to that match.
$name = "pete";
$name = strtolower( $name);
switch( $name )
case "paul": echo "Paul plays bass";
case "john": echo "John plays guitar";
case "george": echo "George plays electric guitar";
case "pete": echo $name . " plays drums";
default: echo "That is not a Beatle";
A variable starts with the $ sign, followed by the name of the variable. Variables are used to store data. Variable values can change over the course of a script.
- A variable does not need to be declared before adding a value to it
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0–9, and _ )
// this is a comment
/* this is also a comment */
$myName = "Thai";
echo "Hello, " . $myName;
$favorite_color = "purple";
echo "Your favorite color is " . $favorite_color;
$favoriteColor2 = "pink";
echo "Sometimes you also like " . $favoriteColor2;
The while loop statement tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE.
$age = 10;
while( $age <20 )
It’s a document that containing empty fields, that the user can fill the data or user can select the data.
<form name= "frmSignup" method="get" action="processForm.php">
Name: <input type="text" name="firstName" />
Age: <input type="text" name="age" />
Favorite Color: <input type="text" name="favoriteColor" />
<input type="submit" name="btnSubmit" value="Process Form" />
For loops statements are the most complex loops in PHP. They behave like their C counterparts.
for( $i = 0; $i < 5; $i++ )
echo "Hello! <br />";
for( $j = 0; $j < 3; $j++ )
echo "---Goodbye!<br />";
for( $k = 1; $k < 7; $k++ )
echo "Have a nice day! <br />";
The PHP increment operators are used to increment a variable’s value.
- They only affect numbers and strings
- Arrays, objects and resources are not affected
$years = 15;
// echo "Adam Levine has been singing for " . $years . " years";
echo "Adam Levine has been singing for " . $years-- . " years";
echo "<br>Adam has NOW been singing for " . $years . "years";
$myAge = 12;
// $myAge = $myAge + 6;
$myAge += 6;
echo "<br />my age is " . $myAge;
BAVC provides multi-media training, career counseling, and support for independent media-makers in the San Francisco…bavc.org
HTML Tag Reference HTML Event Reference HTML Color Reference HTML Attribute Reference HTML Canvas Reference HTML SVG…www.w3schools.com
The PHP development team announces the immediate availability of PHP 5.6.31. This is a security release. Several…php.net
MAMP installs a local server environment in a matter of seconds on your Mac or Windows computerwww.mamp.info
Sublime Text is a sophisticated text editor for code, markup and prose.You'll love the slick user interface…www.sublimetext.com