Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active October 26, 2025 07:31
Show Gist options
  • Save JeffreyWay/25076f684a3e1cba9869772095b166fd to your computer and use it in GitHub Desktop.
Save JeffreyWay/25076f684a3e1cba9869772095b166fd to your computer and use it in GitHub Desktop.
PHP For Beginners, Episode 5 - Conditionals and Booleans
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
</head>
<body>
<h1>
<?= 'Hello World' ?>
</h1>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
<style>
body {
display: grid;
place-items: center;
height: 100vh;
margin: 0;
font-family: sans-serif;
}
</style>
</head>
<body>
<?php
$name = "Dark Matter";
$read = true;
if ($read) {
$message = "You have read $name";
} else {
$message = "You have NOT read $name";
}
?>
<h1>
<?= $message ?>
</h1>
</body>
</html>
@MatimotTheTimoters
Copy link

<?php

/* __________________________________________________
Booleans
Define a variable called $finished and make it equal to false.
*/
$finished = false;

/* __________________________________________________
Conditionals
Change the value of $message by updating the $finished variable to true.
*/
$name = 'The Martian';
$finished = true;

if ($finished) {
    $message = "I finished reading $name";
} else {
    $message = "I am currently reading $name";
}

echo $message;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment