1/29
Coverage: Page 9 - 48 (PHP module) (GLHF in your exams!)
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is PHP Syntax?
It is defined as the structure of statements in a computer language.
What is the element “?>”
It is used to end the script.
(True or False) In a PHP, is everything in a statement a PHP command?
False. Not every word or token in a statement is a PHP command. Additionally, a PHP file may contain PHP script(s), HTML documents, or HTML elements.
It’s used to display a text or value of a variable.
Echo.
What is a single-line comment?
It generally starts with “//”. It’s a one-line explanation or note.
How do you usually create, save, and execute a PHP file?
Firstly, start a server (for instance, wampserver64). Then, open a text editor program and make a PHP script (notepad++). Thirdly, Save the PHP script and lastly, the file must be saved in the server (c: → wamp64 → www.).
What is a PHP variable?
It’s a variable used as a container for storing data. You can assign the value, change the value, or manipulate the value.
(True or False) Variable names should start with a number first before the letter.
False. The program will not work operationally because the variable “$1num” may cause the website to error or not work properly.
How many rules exactly are there in naming a variable.
There are 5 rules in naming a variable respectively.
What is an assignment operator?
It is used to assign a value to a variable.
What is a concatenation operator?
It is used to join two strings or values together.
What are the different classifications of PHP operators?
There are specifically 5 arithmetic operators in PHP. Namely, addition, subtraction, multiplication, division, and modulus or the percentage.
How do you implement and use the concatenation operator in a PHP structure? (Excluding HTML structure).
echo $a . $b;
(True or False) Does the $_POST function usually collect data and the values in the HTML form are shown on the URL or browser’s address bar?
False. It’s the $_GET function.
How does the $_POST function works? (Excluding HTML structure).
<form action = ‘sampleform.php’ method = ‘post’>
What is the condition statement?
It uses an expression answerable by yes/no or true or false.
What is a logical operator?
A logical operator connects conditions and returns true or false based on their combined truth values.
(True or False) Is equal operator “==“ and “=“ similar to one another?
False. When we refer to the variable “=“, it’s an assignment operator which is used to assign a value to a variable. Meanwhile, the equality operator “==“ compares two values to check if they are equal (as shown in the illustration).
How many condition statements are there in PHP?
There are 4 types, respectively, if statement, if…else statement, if…else…if statement, and switch statement (not often used).
What are the contents of an if statement? (Excluding HTML structure)
if (condition)
{
codes to be executed once the condition is true;
}
What are the contents of an if…else…if statement? (Excluding HTML structure)
if (condition1)
{
codes to be executed once the condition1 is true;
}
else if (condition2)
{
codes to be executed once the condition2 is true;
}
else
{
codes to be executed once all the conditions are false;
}
What are the contents of an if…else statement? (Excluding HTML structure)
if (condition)
{
codes to be executed once the condition is true;
}
else
{
codes to be executed once the condition is false;
}
What are the contents of an switch case statement? (Excluding HTML structure)
Switch (condition)
{
case value1:
// codes to be executed if the case value1 meets the condition;
break;
case value2:
// codes to be executed if the case value2 meets the condition;
break;
default:
// codes to be executed if no case value meet the condition;
}
It’s a control structure that executes a statement or block of codes several times depending on the given condition statement.
Loop. It uses either comparison or logical operators to control the number of repetitions (FOR, WHILE, and DO WHILE).
What are the contents of a FOR loop?
for (initialize; condition; increment)
{
// codes to be executed;
// this part is called the loop body;
}
(True or False) If the word “Philippine School Doha” is repeated 12 times, is this execution correct? “for ($x = 1; $x <= 12.1; $x = $x + 1)
{
echo “Philippine School Doha“;
echo “<br>”;
}
False. Because the “condition” statement (12.1) is inputted incorrectly. Causing the website to malfunction once it’s executed.
What is the purpose of the while loop?
It repeatedly executes code as long as the given condition remains true.
What is the purpose of the for loop?
It’s coded a set number of times, based on initialization, condition, and increment.
What is the purpose of the do while loop?
It runs code at least once, then repeats it while the condition remains true.
Make a program that will input any number x and display all numbers from -x to x.
HTML (The bolded texts are the variables/elements that are replaceable)
<!DOCTYPE HTML>
<html>
<head>
<title>Sample.html</title>
</head>
<body>
<form action = ‘Sample.php’ method = ‘post’>
<input type= ‘text’ name = ‘num1’ placeholder = ‘number displayer’>
<input type = ‘submit’ value = ‘Compute’>
</form>
</body>
</html>
PHP
<!DOCTYPE HTML>
<html>
<head>
<title>Sample.php</title>
</head>
<body>
<?php
$x = $_POST [‘num1‘];
while ($x <= 10)
{
echo $x;
echo “<br>”;
$x = $x + 1;
}
?>
</body>
</html>