Understanding PHP Basics
Which of the following is true about PHP as described in the context of web development?
- A. PHP is a client-side scripting language embedded in CSS.
- B. PHP is a server-side scripting language that can be embedded with HTML.
- C. PHP compiles directly to machine code before being run.
- D. PHP is strictly used for mobile app development.
- E. PHP only runs on Windows operating systems.
PHP Redirection
What is the correct PHP function to redirect users to a different page, for example, after submitting a form?
- A. redirect_to('newpage.php');
- B. move('newpage.php');
- C. header('Location: newpage.php');
- D. navigate('newpage.php');
- E. location('newpage.php');
Session Functions Distinction
Which of the following best explains the main difference between session_unset() and session_destroy() in PHP?
- A. session_unset() deletes the session file; session_destroy() clears only the variables.
- B. session_unset() clears session variables, leaving the session active; session_destroy() removes all data and invalidates the session.
- C. session_destroy() only deletes cookies; session_unset() removes the entire session.
- D. Both session_unset() and session_destroy() do exactly the same thing.
- E. Session functions can only be used in PHP 5.6 and below.
PHP Variable Naming
Which of the following is an invalid PHP variable name?
- A. $variable_1
- B. $_userName
- C. $3variable
- D. $user_name3
- E. $Variable
PHP Array Handling
Suppose you want to count the number of elements in a PHP array called $colors. Which function should you use?
- A. length($colors)
- B. sizeof($colors)
- C. count($colors)
- D. elements($colors)
- E. num($colors)
Error Reporting in PHP
What is the effect of setting error_reporting(0) in a PHP script?
- A. Only critical errors are displayed.
- B. Syntax errors get highlighted.
- C. No error messages are shown during the execution of the script.
- D. All errors and warnings are shown vividly.
- E. The script execution stops immediately on error.
PHP Data Types
If $x is defined as $x = array('apple', 'banana', 'cherry'); what is the data type of $x?
- A. String
- B. Integer
- C. Array
- D. Object
- E. Boolean
String Concatenation
How do you concatenate two strings 'Hello' and 'World' in PHP?
- A. 'Hello' + 'World';
- B. concat('Hello', 'World');
- C. 'Hello' . 'World';
- D. 'Hello' u0026 'World';
- E. join('Hello', 'World');
Superglobal Variables
Which PHP superglobal variable is used to access form data sent via the HTTP POST method?
- A. $_COOKIE
- B. $_POST
- C. $_SERVER
- D. $_SESSION
- E. $GLOBALS
PHP and Database Interaction
Which of the following is typically used to connect PHP to a database when building dynamic web pages?
- A. file_connect()
- B. mysql_connect()
- C. data_link()
- D. db_connecter()
- E. connectSQL()