What is the purpose of the 'final' keyword in PHP?
- A) To declare a variable as constant
- B) To prevent a class from being inherited
- C) To prevent a method from being overridden
- D) Both B and C
Which of the following is NOT a valid way to create an array in PHP?
- A) $array = array();
- B) $array = [];
- C) $array = new Array();
- D) $array = array(1, 2, 3);
What is the correct way to define a constant in PHP?
- A) define('CONSTANT_NAME', 'value');
- B) const CONSTANT_NAME = 'value';
- C) constant('CONSTANT_NAME', 'value');
- D) A and B
How can you include a file in PHP?
- A) include('filename.php');
- B) require('filename.php');
- C) Both A and B
- D) import('filename.php');
What is the primary purpose of PHP?
- A) To create static websites
- B) To manage databases
- C) To develop dynamic web applications
- D) To design graphics
Show Answer
Correct Answer: C - To develop dynamic web applications
How can you prevent SQL injection in PHP?
- A) By using the mysql_escape_string() function
- B) By using prepared statements with PDO or MySQLi
- C) By validating user input
- D) By using the htmlspecialchars() function
Show Answer
Correct Answer: B - By using prepared statements with PDO or MySQLi
How can you start a session in PHP?
- A) session_start();
- B) start_session();
- C) begin_session();
- D) initiate_session();
Which of the following is the correct way to declare a variable in PHP?
- A) var $variable_name;
- B) $variable_name;
- C) variable $variable_name;
- D) declare $variable_name;
How can you retrieve the value of a cookie in PHP?
- A) $_COOKIE['cookie_name'];
- B) get_cookie('cookie_name');
- C) cookie('cookie_name');
- D) retrieve_cookie('cookie_name');
Show Answer
Correct Answer: A - $_COOKIE['cookie_name'];
Which of the following is a valid way to declare an array in PHP?
- A) $array = array();
- B) $array = [];
- C) Both A and B
- D) $array = new Array();
What is the purpose of the 'require_once()' function in PHP?
- A) To include a file only once during the script execution
- B) To include a file multiple times
- C) To include a file if it exists
- D) To create a new file
Show Answer
Correct Answer: A - To include a file only once during the script execution
Which of the following is true about PHP variables?
- A) Variables in PHP are case-sensitive
- B) Variables must be declared before use
- C) Variables can only contain letters and numbers
- D) Variables are defined using the 'var' keyword
Show Answer
Correct Answer: A - Variables in PHP are case-sensitive
Which of the following is the correct way to start a session in PHP?
- A) session_start();
- B) start_session();
- C) begin_session();
- D) init_session();
What is the purpose of the 'require_once' statement in PHP?
- A) To include a file only once during script execution
- B) To include a file multiple times
- C) To include a file if it exists
- D) To require a file from a remote server
Show Answer
Correct Answer: A - To include a file only once during script execution
Which of the following is used to handle errors in PHP?
- A) try-catch block
- B) error_reporting() function
- C) set_error_handler() function
- D) All of the above
What is the purpose of the 'foreach' loop in PHP?
- A) To iterate over arrays
- B) To iterate over objects
- C) To iterate over strings
- D) Both A and B
Which of the following is used to handle exceptions in PHP?
- A) try-catch block
- B) if-else statement
- C) error handling function
- D) exception function
What does the 'isset()' function do in PHP?
- A) Checks if a variable is set and is not NULL
- B) Checks if a variable is empty
- C) Initializes a variable
- D) Deletes a variable
Show Answer
Correct Answer: A - Checks if a variable is set and is not NULL
What is the correct way to create a function in PHP?
- A) function myFunction() {}
- B) create function myFunction() {}
- C) def myFunction() {}
- D) function: myFunction() {}
Show Answer
Correct Answer: A - function myFunction() {}
How can you create a session in PHP?
- A) session_start()
- B) start_session()
- C) create_session()
- D) begin_session()
How do you access a session variable in PHP?
- A) $_SESSION['variable_name']
- B) session['variable_name']
- C) $SESSION['variable_name']
- D) session.get('variable_name')
Show Answer
Correct Answer: A - $_SESSION['variable_name']
Which of the following functions is used to connect to a MySQL database in PHP?
- A) mysql_connect()
- B) db_connect()
- C) connect_mysql()
- D) mysqli_connect()
Which of the following is a feature of PHP?
- A) Static typing
- B) Dynamic typing
- C) Compiled language
- D) Case-sensitive variables
What is the purpose of the 'require_once()' function?
- A) To include a file only once
- B) To include a file multiple times
- C) To include a file if it exists
- D) To include a file with error handling
Show Answer
Correct Answer: A - To include a file only once
Which of the following functions can be used to escape special characters in a string for use in SQL queries?
- A) escape_string()
- B) mysql_escape_string()
- C) mysqli_real_escape_string()
- D) sql_escape_string()
Show Answer
Correct Answer: C - mysqli_real_escape_string()