1.
What will be printed?if ('2' == '02') { echo 'true';} else { echo 'false';}
Correct Answer
A. True
Explanation
The given code will print "true". This is because the comparison operator used is the loose equality operator (==), which does not consider the data types of the operands. In this case, both '2' and '02' are considered equal because they have the same characters. Therefore, the condition ('2' == '02') evaluates to true, and the code block inside the if statement is executed, resulting in the output "true".
2.
Which of the following is NOT a valid pHP comparison operator?
Correct Answer
C.
Explanation
The comparison operator "===" is a valid PHP comparison operator. It is used to compare both the value and the type of two variables. The "!=" operator is used to check if two values are not equal, while the ">=" operator is used to check if the left operand is greater than or equal to the right operand. Therefore, the correct answer is ">=".
3.
What will be printed?$a = array( null => 'a', true => 'b', false => 'c', 0 => 'd', 1 => 'e', '' => 'f');echo count($a), "\n";
Correct Answer
B. 3
Explanation
Keys will be converted like this: null to '' (empty string), true to 1, false to 0
4.
What gets printed?class MyException extends Exception {}try { throw new MyException('Oops!');} catch (Exception $e) { echo "Caught Exception\n";} catch (MyException $e) { echo "Caught MyException\n";}
Correct Answer
A. Caught Exception
Explanation
The first catch will match because MyException is a subclass of Exception, so the second catch is unreachable
5.
What will be printed?$a = array();if ($a[1]) null;echo count($a), "\n";
Correct Answer
A. 0
Explanation
checking value in if() does not create an array element
6.
What gets printed?$str = 'a\\b\n'; echo $str;
Correct Answer
C. A\b\n
Explanation
\\ is a special case in single-quoted string literals, which gives a single \, \n is not interpolated in single-quoted string literals
7.
What is a correct way of defining constants in pHP
Correct Answer
D. Define("Constant");
Explanation
The correct way of defining constants in PHP is by using the "define" function followed by the constant name in quotes. This function allows us to define a constant with a specific value, which cannot be changed throughout the execution of the script.
8.
Which function will you use to convert an HTML page into a format that can be saved in database conveniently
Correct Answer
B. Htmlentities()
Explanation
The htmlentities() function is used to convert special characters in an HTML page into their corresponding HTML entities. By using this function, any special characters in the HTML code will be converted into a format that can be safely stored in a database. This ensures that the HTML code is properly encoded and can be easily retrieved and displayed without causing any issues or conflicts with the database.
9.
Which of the following functions will be used to create a CURL sessions
Correct Answer
C. Curl_init()
Explanation
The function curl_init() is used to initialize a CURL session. This function returns a CURL handle, which is then used as the parameter for other CURL functions like curl_setopt() to set various options for the session. Once the session is initialized and options are set, the session can be executed using curl_exec() to perform the desired tasks like making HTTP requests and retrieving data from a remote server. Therefore, curl_init() is the correct function to create a CURL session.
10.
Which of the following is true about GET & POST methods
Correct Answer
C. Using POST, you can hide form data from being viewed on address bar or browser
Explanation
The POST method allows for the submission of form data without displaying it in the address bar or browser. This is useful when dealing with sensitive information that should not be visible to the user or easily accessible. With the GET method, the variables are displayed in the URL of the address bar, making them visible and potentially accessible to anyone who sees the URL. Additionally, the $_REQUEST[] server-side array can access both GET and POST variables, so the statement that POST variables cannot be accessed by $_REQUEST[] is incorrect.
11.
Which of following statements will be used to fetch SINGLE record from a MySql resultset
Correct Answer
D. Mysql_fetch_row
Explanation
The function mysql_fetch_row is used to fetch a single record from a MySQL resultset. It returns an indexed array that contains the values of the fetched row. This function is commonly used when the resultset contains a large number of rows and the memory usage needs to be optimized.
12.
What is correct syntax of connecting to a MySql database
Correct Answer
C. Mysql_connect("localhost",$username,$password)
Explanation
The correct syntax for connecting to a MySql database is "mysql_connect("localhost",$username,$password)". This syntax specifies the host as "localhost" and includes the variables $username and $password, which hold the login credentials for the database.
13.
Which of the following functions MUST be called AFTER using mysql_connect() function
Correct Answer
C. Mysql_select_db
Explanation
The function mysql_select_db must be called after using mysql_connect() because it is used to select a specific database to work with. Once the connection to the MySQL server is established using mysql_connect(), this function is necessary to specify the database that will be accessed for subsequent queries and operations.
14.
What gets printed?<?php$RESULT = 11 + 011 + 0x11;echo "$RESULT";?>
Correct Answer
D. 37
Explanation
A decimal plus an octal plus a hex number. 11 + 9 + 17 = 37
15.
What will be the value of $var below?$var = true ? '1' : false ? '2' : '3';
Correct Answer
B. 2
Explanation
In the given code, the value of $var is determined using the ternary operator. The first condition is true, so the value '1' is assigned to $var. However, this is followed by another ternary operator where the condition is false. In this case, the value '2' is assigned to $var. Therefore, the final value of $var is '2'.