menu

Web Development With PHP


1. Which PHP function is used to encode data in JSON format?

json_encode()

encode_json()

json()

json_format()


2. Which of the following is NOT a valid way to access an element in an array in PHP?

$array[0]

$array{"key"}

$array["key"]

$array->key


3. Which PHP function is used to get the current date and time?

time()

date()

datetime()

now()


4. Which PHP function is used to establish a connection to a MySQL database?

mysql_connect()

mysqli_connect()

pdo_connect()

sql_connect()


5. Which PHP function is used to check if a file exists?

file_exists()

check_file()

exists_file()

file_check()


6. Which of the following is NOT a way to prevent SQL injection attacks in PHP?

Use prepared statements

Sanitize user input

Use mysqli functions instead of mysql functions

Allow raw user input in SQL queries


7. Which of the following is a superglobal variable in PHP?

$_SESSION

$_COOKIE

$_POST

All of the above


8. Which of the following is NOT a valid data type in PHP?

boolean

integer

float

char


9. Which of the following is NOT a way to run PHP scripts?

Through a web server

Through a command line interface

Through a standalone interpreter

Through a database management system


10. Which of the following is NOT a valid way to declare a variable in PHP?

$variable = "value";

var $variable = "value";

$variable = array("value1", "value2");

$variable = 123;