Loïc TRUCHOT
JavaScript Fullstack Expert & Senior web developer
April 2019
By Loïc TRUCHOT
Bonus : Bootstrap, JQuery
add a <h2></h2>, say "hello" to your neighbor here
click "Interpret" button
<h1>Pizza YOLO</h1>
<h2>Hello Sonia !</h2>
<p>
Today is friday: week-end is coming.<br />
What about a delicious Pizza tonight, Sonia ?
</p>
<div>
Try our classics :
<ul>
<li>Vegeteriana</li>
<li>Il Diavolo</li>
<li>Quattro Formagi</li>
</ul>
Or choose the daily chef choice:
<strong>the Calzone</strong>
</div>
<p>
<em>Pizza price: 10 € - See you soon Sonia.</em>
</p>
step 1
<?php
$name;
?>
<h1>Pizza YOLO</h1>
<h2>Hello <?php echo "Sonia"; ?> !</h2>
step 2
<?php
$name = "Sonia";
?>
<h1>Pizza YOLO</h1>
<h2>Hello <?php echo $name ?> !</h2>
<?php
$firstname = "Samir";
$lastname = "Hanini";
?>
<h1>Pizza YOLO</h1>
<h2>Hello <?php echo $firstname; ?> !</h2>
step 3
<?php
$nbOfPizza = 5;
$price = 10;
$discount = 0.2;
?>
<strong>Total: </strong>
<?php
$isConnected = true;
$hasDiscount = true;
?>
<strong>Is connected and has discount : </strong>
<?php
$name;
?>
<h1>PHPizza</h1>
<?php
if (isset($name)) {
echo "<h2>Hello $name !</h2>";
} else {
echo "Please, <button>log in</button>";
}
?>
step 1
<?php
$discountCode = "abc";
$isLogin = false;
$name;
echo "<header>Hello "
. ($isLogin ? $name : "you")
. "</header>";
switch ($discountCode) {
case "abc":
echo "10€ de réduction";
break;
case "def":
echo "20€ de réduction";
break;
default:
echo "Pas de réduction";
}
?>
step 2
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
step 1
<?php
for($x = 1; $x <= 5; $x++) {
echo "The number is: $x <br>";
}
?>
step 2
<?php
$list = array("Pascal", 45, "Coach", false, "Amsterdam");
echo "His name is " . $list[0] .", he live in ". $list[4];
?>
step 1
<?php
$birds = array("cardinal", "kestrel", "kite", "mockingbird");
foreach($birds as $bird) {
echo $bird . " says tweet tweet.<br />";
}
shuffle($birds);
foreach($birds as $index => $bird) {
echo $bird . " is now n°" . $index . " in the list<br />";
}
?>
step 2
<?php
$person = array(
"name" => "Pascal",
"age" => 45,
"job" => "Coach",
"married" => false,
'city' => "Amsterdam");
echo "His name is " . $person["name"] .", he live in ". $person["city"];
foreach($person as $key => $value) {
echo "$key: $value</br>";
}
?>
step 1
Text
Text
Text
<?php
$person = array(
array("first" => "Nicolas", "last" => "Cage"),
array("first" => "John", "last" => "Travolta"),
);
foreach($person as $value) {
echo $value["first"] . " " . $value["last"] . "</br>";
}
?>
step 2
<?php
// declaration (nothing happen)
function say_hello () {
echo "hello<br/>";
}
// execute 2 times (write "hello<br/>" 2 times)
say_hello();
say_hello();
?>
step 1
<?php
function add($a, $b) {
return $a + $b;
}
echo add(3, 5);
echo add(198708, 12349);
?>
step 2
function checkToDo($isDone) {
if ($isDone == true) {
return "the task is done.";
} else {
return "the task is not done.";
}
// following statement will never be evaluated
echo "this will not happen";
}
step 3
function test ($a) {
$b = $a * 2;
// nothing returned ?
}
echo (test(42) == NULL); // will be TRUE and log "1"
Write a function that can perform some quizz
$quizz = array(
array("q" => "Hélium", "a" => "He"),
array("q" => "Oxygène", "a" => "O"),
// and at least 2 more similar Question/Answer
);
function add2 ($n) {
return $n + 2;
}
add2(2);
add2(2);
step 6
$age = 33;
function happyBirthday (&$n) {
$n = $n + 1;
}
happyBirthday($age);
happyBirthday($age);
echo $age;
THANKS EVERYONE
It's finally done !
See you soon with a "Deeper PHP" module
By Loïc TRUCHOT
Discovering computer science basis with some PHP examples