What I learned in My PHP Bootcamp

Thaisa Fernandes
PM101
Published in
6 min readAug 28, 2017

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.

The PHP mascot is the elePHPant, isn’t cool? It’s a blue — weird — elephant.

What does it mean?

PHP is a language designed primarily for web development but can also be used as a general-purpose programming language. What distinguishes PHP from something like JavaScript is that the code is executed on the server. PHP is enclosed in special start and end processing instructions (for opening,<?php and for closing ?>). It allows you to jump into and out of PHP mode.

<!DOCTYPE html>
<html>
<head>
<title>PHP is cool</title>
</head>
<body>
<?php echo '<p>Hello Medium</p>'; ?>
</body>
</html>

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.

Functions

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.

<?

function sayHello()
{
echo "Hello!";
echo " and welcome to my Blog!" ;
}


echo "Today is Sunday August 28th, 2017. <br />";
sayHello();
sayHello();
sayHello();
sayHello();

?>

Array

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 />";
}


?>

If else

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.";
}
else
{
echo "Sorry, you are too young.<br />";
echo "Come back in a few years.";
}

?>

Process form

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 "<br>";
echo "The age entered was " . $_GET[ "age"];
echo "<br>";
echo "Favorite color is " . $_GET[ "favoriteColor"];

?>

Switch-case

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";
break;
case "john": echo "John plays guitar";
break;
case "george": echo "George plays electric guitar";
break;
case "ringo":
case "pete": echo $name . " plays drums";
break;

default: echo "That is not a Beatle";
break;
}

Variables

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.

Note:

  • 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;

?>

While Loop

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 )
{
echo "Hello!<br>";
$age++;
}

?>

Signup Form

It’s a document that containing empty fields, that the user can fill the data or user can select the data.

<!DOCTYPE html>
<html>
<head>
<title>signup form</title>
</head>

<form name= "frmSignup" method="get" action="processForm.php">

Name: <input type="text" name="firstName" />
<br>
Age: <input type="text" name="age" />
<br>
Favorite Color: <input type="text" name="favoriteColor" />
<br>
<input type="submit" name="btnSubmit" value="Process Form" />

</form>

</body>
</html>

For Loops

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 />";
}
}
}

?>

Increment

The PHP increment operators are used to increment a variable’s value.

Note:

  • They only affect numbers and strings
  • Arrays, objects and resources are not affected
<?

$years = 15;

// $years++;
// 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;


?>

I want to acknowledge my teacher, Nolan Erck, who taught me the PHP class at BAVC and showed me most of the code samples I’m sharing with you in this post.

👋 Feel Free to Clap and Share your Thoughts!

Find more at our LinkedIn, Instagram, and Twitter. Check our podcast. Follow our LinkedIn page and Newsletter!

Disclosure: At PM101, we strive to provide our readers with valuable and honest information on Product and Program Management. As a way to support the blog and continue providing valuable content, some blog posts may contain affiliate links or promotional content. By clicking on these links and making a purchase, the writer may receive a small commission at no additional cost to you. This commission helps to keep the blog running and allows the writer to continue providing valuable content and increasing her coffee and kombucha consumption. Rest assured, we will always provide honest and informative content and use affiliate links and promotional content only as a means to generate revenue to support the blog.

--

--

Thaisa Fernandes
PM101
Editor for

Program Management & Product Management | Podcast Host | Co-Author | PSPO, PMP, PSM Certified 🌈🌱