CS310 – Open Source Web Application Development (PHP): Midterm Important MCQs (53 Solved Questions)
Computer Science • Read every solved MCQ with its verified answer key directly on this page. Free, no login required.
All 664 Midterm Packs · CS310 Course Page · CS310 Subjective Pack (41 Q&As)
-
PHP Stands for ________________.
Topic: PHP Basics & Syntax
- PHP Hypertext Preprocessor ✓ Correct answer
- Personal Hypertext Page
- Power Home Page
- Personal Hyper Preprocessor
-
PHP is ___________ to use.
Topic: PHP Basics & Syntax
- Free ✓ Correct answer
- Paid
- Adware
- None of the given options
-
With PHP we can _______________.
Topic: PHP Basics & Syntax
- Generate dynamic page content
- Collect form data
- Manage cookies
- All of the given options ✓ Correct answer
-
In PHP single line comments can be given using ______________.
Topic: PHP Basics & Syntax
- // ✓ Correct answer
- **
- $
- @
-
In PHP multiline comments can be given using __________________.
Topic: PHP Basics & Syntax
- /**/ ✓ Correct answer
- /# #/
- /^ ^/
- /@ @/
-
In PHP, a variable starts with a ________________ sign followed by the name of variable.
Topic: PHP Basics & Syntax
- #
- $ ✓ Correct answer
- &
- @
-
In PHP ______________ is used to mark the end of statement.
Topic: PHP Basics & Syntax
- ; (Semicolon) ✓ Correct answer
- . (Dot)
- : (Colon)
- # (Hash)
-
A PHP variable can have ___________ scope.
Topic: Variables, Constants & Scope
- local
- global
- static
- All of the given options ✓ Correct answer
-
A variable declared outside a function has ____________ scope.
Topic: Variables, Constants & Scope
- Local
- Global ✓ Correct answer
- Static
- None of the given options.
-
In PHP Constants have ___________ scope.
Topic: Variables, Constants & Scope
- Local
- Global ✓ Correct answer
- Static
- None of the given options.
-
________ is exponent operator in PHP
Topic: Operators
- ** ✓ Correct answer
- #
- $
- ^
-
______________ is logical AND operator in PHP.
Topic: Operators
- && ✓ Correct answer
- !!
- &
- **
-
______________ is an increment operator in PHP.
Topic: Operators
- ++ ✓ Correct answer
- **
- ||
- ^^
-
Which of the following statement is used to execute some code if one of the several conditions is true?
Topic: Control Structures (if / else)
- if statement
- if else statement
- if-elseif-else statement ✓ Correct answer
- None of the given
-
Which of the following statement is used when we want to perform some action if the condition is true and another action if condition is false?
Topic: Control Structures (if / else)
- if statement
- if else statement ✓ Correct answer
- if-elseif-else statement
- switch statement
-
For which value of variable $a, the condition of following if statement will be true? if($a > 10)
Topic: Control Structures (if / else)
- $a = 0
- $a = 15 ✓ Correct answer
- $a = 5
- $a = 10
-
What will be the output of following code segment? $n = 5 ; if($n > 10) echo "Number is greater than 10" ; else echo "Number is not greater than 10" ;
Topic: Control Structures (if / else)
- Number is greater than 10
- Number is 5
- Number is not greater than 10 ✓ Correct answer
- No output will be displayed
-
Which of the following is the correct syntax of for loop in PHP?
Topic: Loops
- for($i=0; $i<5: $i++)
- for($i=0; $i<5; $i++) ✓ Correct answer
- for($i=0; $i<4, $i++)
- for($i=0; $i<4: $i++)
-
Consider the following code given below: for($i=0; $i<4; $i++) echo "i=$i"; How many times the above loop will be executed?
Topic: Loops
- 2
- 3
- 4 ✓ Correct answer
- 5
-
If the exact iteration of loop is known then which of the following loop should be used?
Topic: Loops
- while loop
- do while loop
- for loop ✓ Correct answer
- foreach loop
-
Which of the following loop should be executed at least one time during the execution of loop?
Topic: Loops
- for loop
- foreach loop
- while loop
- do while loop ✓ Correct answer
-
In which of the following loop, first the body of loop is executed and then condition is checked?
Topic: Loops
- for loop
- while loop
- do while loop ✓ Correct answer
- foreach loop
-
In PHP which of the following statements takes all the text/code/markup that exists in the specified file and copies it into the file in which this statement is used?
Topic: Include Statement & date() Function
- Add File
- Include ✓ Correct answer
- Copy File
- Echo
-
What is the correct syntax of writing include statement in PHP from the followings?
Topic: Include Statement & date() Function
- include 'filename'; ✓ Correct answer
- 'filename' include;
- #Includes<>
- #Include{ }
-
The character that is used in format parameter string of date() function of PHP for representing a month is:
Topic: Include Statement & date() Function
- d
- m ✓ Correct answer
- Y
- l
-
In PHP a session is started with the __________ function.
Topic: Sessions
- session_start() ✓ Correct answer
- start_session#()
- start_PHP_session()
- #session_start_this()
-
In PHP Session variables are set with the PHP global variable ____________.
Topic: Sessions
- ##_SESSION
- %_SESSION
- $_SESSION ✓ Correct answer
- @_SESSION
-
To destroy the session in PHP we use _____________.
Topic: Sessions
- destroy();
- session_destroy(); ✓ Correct answer
- session_delete_this();
- session_destroy_current#();
-
Which of the following is used as server-side scripting?
Topic: PHP Basics & Syntax
- PHP ✓ Correct answer
- MS Access
- Oracle
- Apache
-
A PHP script starts with ______ and ends with ______.
Topic: PHP Basics & Syntax
- <?php, ?> ✓ Correct answer
- <?php, ?php>
- <php, php >
- <?, php>
-
Which of the following statement correctly declares a variable named v?
Topic: PHP Basics & Syntax
- $v = 5; ✓ Correct answer
- #v = 5;
- &v = 5;
- v = 5;
-
Which of the following statement is true regarding echo and print?
Topic: PHP Basics & Syntax
- echo has no return value whereas print has a return value of 1 ✓ Correct answer
- Both echo and print returns a value of 1
- echo has a return value of 1 whereas print has no return value
- Both echo and print have no return value
-
PHP is a loosely typed language because ______.
Topic: PHP Basics & Syntax
- It is not case sensitive.
- It doesn't include header files.
- It is user friendly.
- Its value type can be changed any time. ✓ Correct answer
-
What will be the output of following PHP program? <?php $x = "Welcome"; echo "<p>$x!</p>"; echo "$x to Virtual University"; ?>
Topic: PHP Basics & Syntax
- Welcome! Welcome to Virtual University ✓ Correct answer
- Welcome to Virtual University
- Welcome!
- Syntax Error
-
Which of the following statement is true regarding PHP variables?
Topic: Variables, Constants & Scope
- PHP is a strongly typed language.
- PHP automatically converts the variable to correct data type depending on its value. ✓ Correct answer
- None of the given option
- In PHP, the programmer must declare the name and type of the variable before using it.
-
Which of the following keyword is used when we want a local variable NOT to be deleted inside the function after the execution of function?
Topic: Variables, Constants & Scope
- function
- static ✓ Correct answer
- global
- local
-
What will be the output of the following PHP program? <?php $x = 98.765; var_dump ($x); ?>
Topic: Variables, Constants & Scope
- 98.765
- float
- 98.765 (float)
- float(98.765) ✓ Correct answer
-
When the logical operator OR (||) combines two expressions (exp1 and exp2) in IF statement then the result will be true only, __________.
Topic: Operators
- When exp1 is false and exp2 is true
- All of the given options ✓ Correct answer
- When both exp1 and exp2 are true
- When exp1 is true and exp2 is false
-
If $x = 115; and $y = 3; then what will be the output of the following PHP line? $x / $y;
Topic: Operators
- 39
- 38
- 0
- 38.333 ✓ Correct answer
-
If $num1 = 74; and $num2 = 4; then what will be the output of the following PHP line? $num1 % $num2;
Topic: Operators
- 2 ✓ Correct answer
- 4
- 18.5
- 0
-
Which of the following operator is used to compare data type and value of variable?
Topic: Operators
- !=
- <>
- === ✓ Correct answer
- ==
-
Identify the logical error in the following IF condition if( ($i < 5) && ($i > 15) )
Topic: Control Structures (if / else / switch)
- Condition is always true
- & will be used instead of &&
- && cannot be used with if condition
- Condition is always false ✓ Correct answer
-
Find out the logical error in following lines of code. if ($x = 10) echo "The value of x is 10";
Topic: Control Structures (if / else / switch)
- Instead of = we should use == ✓ Correct answer
- There is no semicolon at the end of if condition
- 10 should be enclosed in double quotes
- Variable $x should not be inside parenthesis
-
How many main parameter(s) is/are used in for loop?
Topic: Loops
- 1
- 4
- 2
- 3 ✓ Correct answer
-
PHP supports ______ types of looping techniques.
Topic: Loops
- 5
- 4 ✓ Correct answer
- 2
- 3
-
When the break statement is encountered in a loop's body, it transfers the control __________ from the current iteration of loop.
Topic: Loops
- Outside ✓ Correct answer
- To last iteration
- To first iteration
- Inside
-
What will be the output of following code segment? for ($i = 2; $i < 7; $i++){ if ($i == 5) break; echo $i . " "; }
Topic: Loops
- 2 3 7 8 9
- 4 6 7 8 9
- 2 3 4 6
- 2 3 4 ✓ Correct answer
-
Which of the following is correct way to include "connection.php" file into our current PHP file?
Topic: Include Statement & date() Function
- include "connection.php";
- All of the above options ✓ Correct answer
- include("connection.php");
- include 'connection.php';
-
Which of the following is required parameter of "date()" function in PHP?
Topic: Include Statement & date() Function
- None of the given options
- Timestamp
- Format ✓ Correct answer
- Zone
-
$_SESSION is a/an ____________.
Topic: Cookies & Sessions
- Class
- Function
- Array ✓ Correct answer
- Variable
-
Which of the following function is used to destroy all session variables?
Topic: Cookies & Sessions
- destroy_vars();
- destroy_variables();
- session_unset(); ✓ Correct answer
- session_destroy();
-
Which of the following is correct way to display all session variables?
Topic: Cookies & Sessions
- echo ($_SESSION);
- print_r($_SESSION); ✓ Correct answer
- print ($_SESSION);
- None of the given options
-
Which of the following is correct option regarding cookies?
Topic: Cookies & Sessions
- All of the given options ✓ Correct answer
- A cookie is a small file that the server embeds on the user's computer.
- Each time the same computer requests a page with a browser, it will send the cookie too.
- With PHP, you can both create and retrieve cookie values.