PHP Basics - syntax, variables, data types, operators, control structures, mixing PHP with HTML - One Line Questions
1.
Which PHP superglobal array contains all the variables from GET, POST and COOKIE? —
`$_REQUEST`
2.
PHP variables are case-sensitive. Which of the following are different variables? —
`$myVar`, `$myvar`, `$MYVAR`
3.
What is the PHP operator for subtraction? —
-
4.
What is the PHP operator for logical NOT? —
!
5.
What is the PHP operator for comparison (not equal to)? —
!=
6.
Which symbol is used to end a PHP code block? —
?>
7.
Which operator is used for string concatenation in PHP? —
.
8.
What is the standard file extension for PHP files? —
.php
9.
What is the PHP operator for multiplication? —
*
10.
What is the PHP operator for division? —
/
11.
What is the syntax for a multi-line comment in PHP? —
/* This is a comment */
12.
What is the syntax for a single-line comment in PHP? —
// This is a comment
13.
What is the PHP operator for logical AND? —
&&
14.
What is the PHP operator for modulo (remainder of division)? —
%
15.
What is the PHP operator for addition? —
+
16.
Which symbol is used to start a PHP code block? —
<?php
17.
Which HTML tag is commonly used to embed PHP code within an HTML document? —
It can be embedded anywhere, but the PHP tags <?php ?> are essential.
18.
How do you output the value of a PHP variable `$count` within an HTML paragraph tag? —
Both A and C
19.
What is the PHP operator for assignment? —
=
20.
What is the PHP operator for comparison (equal to)? —
==
21.
What is the PHP operator for comparison (identical to - value and type)? —
===
22.
What is the PHP operator for logical OR? —
||
23.
What is the result of the expression `5 + '2'` in PHP? —
7
24.
What is the result of the expression `'5' + 2` in PHP? —
7
25.
What is the result of the expression `'5 apples' + 2` in PHP? —
7
26.
Which PHP data type is used to store arrays? —
Array
27.
Which PHP data type can store one of two values: TRUE or FALSE? —
Boolean
28.
In a switch statement, what keyword is used to end a case and move to the next? —
break
29.
Which PHP construct is used to define a constant? —
define() function
30.
Which loop structure executes the code block once, and then continues as long as a condition is true? —
do...while loop
31.
Which PHP data type is used to store decimal numbers? —
Float
32.
Which loop structure is used when you know how many times you want to loop? —
for loop
33.
Which loop structure is used to iterate over arrays and objects? —
foreach loop
34.
Consider the following PHP code snippet: `$name = 'World'; echo 'Hello, ' . $name . '!';` What will be the output? —
Hello, World!
35.
Which control structure is used to execute a block of code only if a specified condition is true? —
if statement
36.
Which control structure is used to execute a block of code if a condition is true, and another block if the condition is false? —
if...else statement
37.
Which PHP data type is used to store whole numbers? —
Integer
38.
Which control structure allows you to execute a block of code multiple times? —
Loop
39.
What is the default value for a variable that has been declared but not assigned a value in PHP? —
NULL
40.
Which PHP data type represents an object that has no value? —
NULL
41.
What is the PHP function used to output a string and can accept multiple arguments? —
printf
42.
Which PHP data type is used to store text? —
String
43.
Which control structure is used to execute different blocks of code based on the value of a variable? —
switch statement
44.
What is the purpose of the `empty()` function in PHP? —
To check if a variable is empty, false, 0, '0', NULL, or an empty array.
45.
What is the purpose of mixing PHP with HTML? —
To generate dynamic HTML content based on server-side logic.
46.
If you have an HTML form with a GET method, how can you access the submitted data in PHP? —
Using the `$_GET` superglobal array.
47.
If you have an HTML form with a POST method, how can you access the submitted data in PHP? —
Using the `$_POST` superglobal array.
48.
How do you declare a variable in PHP? —
Using the '$' symbol followed by the variable name.
49.
How can you output a variable's value within an HTML context using PHP? —
All of the above.
50.
Which loop structure continues as long as a condition is true? —
while loop