---
# System prepended metadata

title: PHP Interview Questions

---

# PHP Interview Questions

## Introduction to PHP
* PHP which stands for `PHP:Hypertext Preprocessor` is a widely used open-source server-side scripting language especially suited for creating dynamic websites and mobile API’s. 
* It supports many databases like MySQL, Solid, PostgreSQL, Oracle, Sybase, generic ODBC etc. PHP code is embedded within HTML. 
* It is used to manage dynamic content,  session tracking, databases and also to build an entire e-commerce sites. 
* By default, most of the web hosting servers support PHP and thus it contributes for cost-effectiveness. 

### Features of PHP
1. It is free of cost and open source. It can be downloaded anywhere and readily available to develop web applications.
2.  PHP based applications which are connected to database can be easily loaded . It is mainly used due to its faster rate of loading over slower internet than any other programing language.
3. It is platform independent. PHP based applications can run on any operating systems like UNIX, Linux and Windows etc.
4. Equivalent code  can be reused with the help of PHP. Thus helps in shortening the lengthy code and sophisticated structure for event handling in web applications.
5. It helps to ease the code management.
6. Built-in database connection modules of PHP helps in easier database connection. Thus reduces trouble and time for the development of web applications and content based websites.
7. Flexibility of PHP makes it ready to effectively combine with many other programming languages.

### Uses of PHP
* PHP performs system functions, i.e. from files on a system it can create, read, write, open and close them.
* PHP can handle forms. It collects data from the  files, save data to a file and also through email you can send data, return data to the user.
* It can be used to control user-access.
*  You can restrict users from accessing some pages of your website.
* It helps to access and modify cookies variables.
* We can add, modify and delete elements within the  database through PHP.
* It is helpful in data encryption.

### Scope of PHP
* PHP is a widely used open-source programming language developed for creating dynamic websites and mobile API’s. 
* It is one of the top languages because of its ability to have a large impact on the outcome with very little code. This amount of efficiency has been the requirement for the past few years in the industry. 
* On seeing this, companies are investing a good amount of money in hiring proficient PHP developers to fit these shoes and work effectively.
* Let us see most commonly asked PHP interview question for freshers and experienced in the upcoming sections.

## PHP Interview Questions

### PHP Basic Interview Questions
#### 1. What is PHP?
PHP stands for the recursive acronym "PHP: Hypertext Preprocessor" which was created by Rasmus Lerdorf in the year 1994.  PHP is a open-source, server-side scripting language which is widely used for creating dynamic websites and mobile API’s. PHP scripts are embedded with HTML and executed on the server.

#### 2. Differentiate between variables and constants in PHP.
| Variables | Constants |
| ---------- | ---------- | 
| Value of a variable can be changed during the execution.  |  The constant value can't be changed during script execution.|
|Variables require compulsory usage of the $ sign at the start. |No dollar sign ($) is required before using a constant.|
|It is possible to define a variable by simple assignment.|Constants can't be defined by simple assignment. They are defined using the define() function.|
|The default scope is the current access scope.| Constants can be accessed throughout without any scoping rules.|

#### 3. What is session in PHP?
* A session is a way to store information to be used across multiple pages of an entire website. The information is not stored on the user's computer, unlike cookie.
* In a temporary directory on the server, a file will be created by the session where registered session variables and their values are stored. This information will be available to all pages on the site during that visit.
* When you work with an application, you open it, do some modifications and then you close it. This is much like a Session. The computer knows who you are. It knows when the application is started and ended by you. 
    * But on the internet, the web server does not know who you are or what you do, because the HTTP address doesn't maintain state.
    * This problem is solved using session variables by storing user information to be used across multiple pages (e.g. username, favorite color, etc). 
* By default, session variables will last until the user closes the browser.
* So Session variables hold single user information, and are available to all pages in one application.

#### 4. What does PEAR stands for?
* PEAR stands for "PHP Extension and Application Repository". PEAR is a framework and repository for all of the reusable PHP components. 
* PEAR provides a higher level of programming for web developers. It contains all kind of PHP code snippets and libraries. It also provides you with a command line interface to automatically install packages.

#### 5. Explain the difference between $message and $$message.
| $message | $$message |
| -------- | -------- | 
| $message is a regular variable.|$$message is a reference variable.| 
| It has a fixed name and stores a fixed value.|It stores data about the variable.|
| Data stored in $message is fixed.| The value of $$message can change dynamically as the value of the variable changes.|

#### 6. Is PHP a case sensitive language?
* PHP can be considered as a **partially** case sensitive language. The variable names are completely case-sensitive but function names are not. Also, user-defined functions are not case sensitive but the rest of the language is case-sensitive.
* For example, user-defined functions in PHP can be defined in lowercase but later referred to in uppercase, and it would still function normally.

#### 7. What are the different types of variables present in PHP? 
![](https://i.imgur.com/xgum9g7.png)
There are 8 primary data types in PHP which are used to construct the variables. They are:
1. **Integers:** Integers are whole numbers without a floating point. Ex: 1253.
2. **Doubles:** Doubles are floating point numbers. Ex: 7.876
3. **Booleans:** It represents two logical states- true or false.
4. **NULL:** NULL is a special type that only has one value, NULL. When no value is assigned to a variable, it can be assigned with NULL. 
5. **Arrays:** Array is a named and ordered collection of similar type of data. Ex: `$colors = array("red", "yellow", "blue");`
6. **Strings:** Strings are sequence of characters. Ex: "Hello InterviewBit!"
7. **Resources:** Resources are special variables that consists of references to resources external to PHP(such as database connections).
8. **Objects:** An instance of classes containing data and functions. Ex: `$mango = new Fruit();`

#### 8. What are the rules for naming a PHP variable?
The following two rules are needed to be followed while  naming a PHP variable:
1. A variable must start with a dollar-`$`- symbol, followed by the variable name. For example: `$price=100;` where price is a variable name.
2. Variable names must begin with a letter or underscore.
3. A variable name can consist of letters, numbers or underscores. But you cannot use characters like `+` , `–` ,` %` , `&` etc.
4. A PHP variable name cannot contain spaces.
5. PHP variables are case-sensitive. So $NAME and $name both are treated as different variables.

#### 9. What is the difference between "echo" and "print" in PHP?
| echo | print |
| -------- | -------- | 
|echo can output one or more string.| print can only output one string and it always returns 1.| 
| echo is faster than print because it does not return any value. | print is slower compared to echo.|
| If you want to pass more than one parameter to echo, parenthesis should be used.| Use of parenthesis is not required with the argument list.|

#### 10. Tell me some of the disadvantages of PHP.
PHP has the following disadvantages:
1. For giant content-based web applications, PHP is not suitable.
2. Since it is an open-source, it is not secure.  Because ASCII text file are easily available.
3. Change or modification in core behavior of online applications is not allowed by PHP.
4. If we use more features of PHP framework and tools, it will cause poor performance of online applications.
5. PHP features a poor quality of handling errors. PHP lacks debugging tools, which are needed to look for warnings and  errors. It has only few debugging tools in comparison to other programming languages.

### PHP Intermediate Interview Questions
#### 1. How can PHP and HTML interact?
* PHP scripts have the ability to generate HTML, and it is possible to pass information from HTML to PHP. 
* PHP is a server side language where as HTML is a client side language. So PHP executes on server side and gets its results as strings, objects, arrays, and then we use them to display its values in HTML. 
* This interaction helps bridge the gaps and use the best of both languages.

#### 2. What is purpose of @ in Php ?
In PHP, @ is used for suppressing error messages. If any runtime error occurs on the line which consists @ symbol at the beginning , then the error will be handled by PHP.

#### 3. Explain the importance of Parser in PHP?
* A PHP parser is a software that converts source code into the code that computer can understand. This means whatever set of instructions we give in the form of PHP code is converted into a machine-readable format by the parser. 
* You can parse PHP code with PHP using the `token_get_all()` function.

#### 4. What are the different types of Array in PHP?
There are 3 main types of arrays that are used in PHP. 
![](https://i.imgur.com/DQPYXt1.png)

1. **Indexed array:** An array with a numeric key is known as the indexed array. Values are stored and accessed in linear order.
![](https://i.imgur.com/p7LmWg0.png)
2. **Associative array:** An array with strings for  indexing elements is known as the associative array.  Element values are stored in association with key values rather than in a strict linear index order.
![](https://i.imgur.com/zI6n7L5.png)
3. **Multidimensional array:** An array containing one or more arrays within itself is known as multidimensional array. The values are accessed using multiple indices.
![](https://i.imgur.com/knN5h6W.png)

#### 5. Explain main types of errors.
There are 3 main types of errors in PHP. They are:
1. **Notices:** Notices are non-critical errors that can occur during the execution of script. These are not visible to users. Example: Accessing an undefined variable.
2. **Warnings:** These are more critical than notices. Warnings don't interrupt the script execution. By default, these are visible to the user. Example: include() a file that doesn't exist.
3. **Fatal:** This is the most critical error type which, when occurs, immediately terminates the execution of script. Example: Accessing a property of a non-existent object or require() a non-existent file.

#### 6. What are traits?
* Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It's not possible to instantiate it on its own.
*  A trait is intended to reduce limitations of single inheritance by enabling a developer to reuse sets of methods freely in many independent classes living in different hierarchies of class. 

#### 7. Does JavaScript interact with PHP?
JavaScript is a client-side programming language, whereas PHP is a server-side scripting language. PHP has the ability to generate JavaScript variables, and this can be executed easily in the browser. Thereby making it possible to pass variables to PHP using a simple URL.

#### 8. How does the ‘foreach’ loop work in PHP?
* The foreach statement is a looping construct which is used in PHP to iterate and loop through the array data type. 
* The working of foreach is simple, with every single pass of the value, elements get assigned a value and pointers are incremented. This process is repeatedly done until the end of the array has been reached.
* The syntax for using the foreach statement in PHP is given below:
    ```
    foreach($array as $value)
    {
        Code inside the loop;
    }
    ```

#### 9. What is the most used method for hashing passwords in PHP?
The crypt() function is used for this functionality as it provides a large amount of hashing algorithms that can be used. These algorithms include sha1, sha256 or md5 which are designed to be very fast and efficient. 

#### 10. What is the difference between the include() and require() functions ?
**include() function:** 
- This function is used to copy all the contents of a file called within the function, text wise into a file from which it is called. 
* When the file being included cannot be found, it will only produce a warning (E_WARNING) and the script will continue the execution.

**require() function:** 
* The require() function performs same as the include() function. It also takes the file that is required and copies the whole code into the file from where the require() function is called. 
* When the file being included cannot be found, it will produce a fatal error (E_COMPILE_ERROR) and terminates the script. 

#### 11. What are cookies? How to create cookies in PHP?
- A cookie is a small record that the server installs on the client's computer. They store data about a user on the browser. It is used to identify a user and is embedded on the user's computer when they request a particular page. 
- Each time a similar PC asks for a page with a program, it will send the cookie as well. 
- After verifying the user's identity in encrypted form, cookies maintain the session id generated at the back end. It must reside in the browser of the machine.
- You can store only string values not object because you cannot access any object across the website or web apps.
- By default, cookies are URL particular. For example, Gmail cookies are not supported by Yahoo and vice versa.
- Cookies are temporary and transitory by default. 
- Per site 20 cookies can be created in a single website or web app.
- 50 bytes is the initial size of the cookie.
- 4096 bytes is the maximum size of the cookie.
- In PHP, we can create cookies using the setcookie() function:
`setcookie(name, value, expire, path, domain, secure, httponly);`
Here name is mandatory and remaining parameters are optional.
Example:
`setcookie(“instrument_selected”, “guitar”)`

#### 12. What is the difference between `ASP.NET` and PHP?
|` ASP.NET `| PHP | 
| -------- | -------- | 
|A web application framework. |  A server side scripting language.  |
|It is designed for use on Windows.| It is Platform independent|
|Code is compiled and executed.|Interpreted mode of execution.|
|It has a license cost associated with it. |PHP is open source and freely available.|

#### 13. What is the meaning of ‘escaping to PHP’?
* The PHP parsing engine needs a way to differentiate PHP code from other page elements. The mechanism to achieve this is known as ‘escaping to PHP’. Escaping a string means to reduce ambiguity in quotes used in that string.
* For example, when you're defining a string, you surround it in either double quotes or single quotes:
 `"Hello InterviewBit." `
- But what if I include double quotes within string?
`"Hello "InterviewBit."" `
Now I have ambiguity - the interpreter doesn't know where does my string ends. 
- If I want to keep my double quotes, I have various options. I could use single quotes around my string:
`'Hello "InterviewBit."' `
Or I can escape my quotes:
`"Hello \"InterviewBit.\"" `
- Any quote that is preceded by a slash is escaped, and understood to be part of the value of the string.

#### 14. Explain Path Traversal.
* Path traversal is a form of attack to read into the files of a web application. `'../'` (dot-dot-sequences) is a cross-platform symbol to go up in the directory. Path traversal makes use of this symbol to operate the web application file.
* The attacker can reveal the content of the file attacked using the path traversal outside the root directory of a web server or application. It is usually done to gain access secret passwords, token and other sensitive information stored in the files.
* Path Traversal is also called as "Directory Traversal". It allows the attacker to exploit vulnerabilities present in the web file under attack.
* Let’s take an simple example. Consider we have a “Show File” button that opens the following URL when clicked:
    `https://www.example.com/show_file.php?file=report.txt`
    * For a classic directory traversal attack, the attacker may try to access the system file `/etc/passwd` (assuming a UNIX/LINUX system) by visiting the URL given below:
    `https://www.example.com/show_file.php?file=../../etc/passwd`
    * If the application receives the value of the file parameter from the URL and passes it to a system call, it would traverse the relative path `../../etc/passwd` starting from `/var/www` and ask the system to load the password file. 
    * This technique is also called a dot-dot-slash attack, because it usually uses the special characters `../` (or `\..` on Windows) to climb to a higher-level directory. 

#### 15. What is the meaning of a final method and a final class?
* The final keyword in a declaration of method indicates that the method cannot be overridden by subclasses. A class which is declared as final cannot be subclassed. 
* This is especially useful when we are creating an immutable class like the String class. Only classes and methods may be declared final, properties cannot be declared  as final.

### PHP Advanced Interview Questions

#### 1.  What are the steps to create a new database using MySQL and PHP?
There are 4 main steps used to create a new MySQL database in PHP. They are given below:
1. A connection establishment is done to the MySQL server using the PHP script.
2. The connection is validated. If the connection is successful, then you can write a sample query to verify.
3. Queries that create the database are input and later stored into a string variable.
4. Then, the created queries will be executed one after the other.

#### 2. What is the use of session_start() and session_destroy() functions in PHP?
The session_start() function is used to start a new session. Also, it can resume an existing session if it is stopped. In this particular case, the return will be the current session if resumed.
Syntax:
`session_start();`

The session_destroy() function is used to destroy all of the session variables as given below:
```
<?php
session_start();
session_destroy();
?>
```

#### 3. What is Memcache and Memcached in PHP? Is it possible to share a single instance of a Memcache between several projects of PHP?
* Memcached is an efficient caching daemon designed specifically for decreasing database load in dynamic web applications. Memcache offers a handy procedural and object-oriented interface to Memcached.
* Memcache is a memory storage space. We can run Memcache on a single or several servers. Therefore, it is possible to share a single instance of Memcache between multiple projects.
* It is possible to configure a client to speak to a separate set of instances. Therefore, it is allowed to run two different Memcache processes on the same host. Despite running on the same host, both of such Memcache processes stay independent, unless there is a partition of data.

#### 4. What are the different ways of handling the result set of MySQL in PHP?
There are 4 ways of handling the result set of MySQL in PHP. They are:
1. `mysqli_fetch_array()`: Returns the current row of result set as an associative array, a numeric array, or both.
2. `mysqli_fetch_assoc()`: Returns the current row of result set as an associative array.
3. `mysqli_fetch_object()`: Returns the current row of a result set, as an object.
4. `mysqli_fetch_row()`: Returns result row as an enumerated array.

#### 5. How to connect to a URL in PHP?
* Any URL can be connected to PHP easily by making use of the library called cURL. This comes as a default library with the standard installation of PHP. 
* The term cURL stands for client-side URL. 
* cURL make use of libcurl(client-side URL Transfer Library) which supports many protocols like FTP, FTPS, HTTP/1, HTTP POST, HTTP PUT, HTTP proxy, HTTPS, IMAP, Kerberos etc.
* It allows you to connect to a URL and retrieve and display information from that page – like the HTML content of the page, HTTP headers and their associated data etc. 
* Steps for connecting with URL using PHP cURL POST are given below:
    * Initialize cURL session.
    * Define your URL where you want to post the request. We can directly enter this URL into URL section in set option parameter or we can assign it to an object.
    * Now, define cURL options which you want to execute with post option. 
    * After setting all the functions then it’s time to execute our cURL.
    * After this, close the cURL and echo your object to check their response.
 
```
//Step 1 To initialize curl
      $ch = curl_init();
//Step 2 To set url where you want to post
      $url = ‘http://www.localhost.com’;
//Step 3 Set curl functions which are needs to you
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_POST,true);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
      curl_setopt($ch,CURLOPT_POSTFIELD,’postv1 = value1&postv2 = value2’);
//Step 4 To execute the curl
      $result = curl_exec($ch);
//Step 5 Close curl
      curl_close($ch);
 ```

#### 6. How to create API in PHP?
API stands for Application Programming Interface. It defines the functions and variables. Communication between the database via php extensions are handled by API.
REST API is the web architecture which uses HTTP protocol for exchanging data between two functions that means your application or system.  Now, let us have a look at how to create REST API in PHP by considering example of accessing data from database using PHP script.
1. **Create a database:** To create database run the query given below:
`CREATE DATABASE phptest;`
2. **Create a table:**  After creating database, you have to create table with dummy data. To create a table run the query given below:
```
CREATE TABLE IF NOT EXISTS `transactions` 
(
    `id` int(20) NOT NULL AUTO_INCREMENT,
    `order_id` int(50) NOT NULL,
    `amount` decimal(9,2) NOT NULL,
    `response_code` int(10) NOT NULL,
    `response_desc` varchar(50) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
```
3. **Create a Database Connection:** Create a `db.php` file and paste the below given database connection in it. Make sure to update these credentials with your database credentials.
```
<?php
// Enter your Host, username, password, database below.
$con = mysqli_connect("localhost","root","","phptest");
if (mysqli_connect_errno())
{
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
     die();
}
?>
 ```
4. **Create a REST API File:** Create a `api.php` file and copy the following script in it.
```
<?php
header("Content-Type:application/json");
if (isset($_GET['order_id']) && $_GET['order_id']!="") 
{
	include('db.php');
	$order_id = $_GET['order_id'];
	$result = mysqli_query($con,
        "SELECT * FROM `transactions` WHERE order_id=$order_id");
	if(mysqli_num_rows($result)>0)
        {
	    $row = mysqli_fetch_array($result);
	    $amount = $row['amount'];
            $response_code = $row['response_code'];
            $response_desc = $row['response_desc'];
	    response($order_id, $amount, $response_code, $response_desc);
	    mysqli_close($con);
	}
        else
        {
		    response(NULL, NULL, 200,"No Record Found");
	}
}
else
{
	response(NULL, NULL, 400,"Request is invalid");
}
function response($order_id,$amount,$response_code, $response_desc)
{
	$response['order_id'] = $order_id;
	$response['amount'] = $amount;
	$response['response_code'] = $response_code;
        $response['response_desc'] = $response_desc;
	$json_response = json_encode($response);
	echo $json_response;
}
?>
```
The above code will accept the GET request and return output in the JSON format.
Now you can get the transaction information by browsing the following URL:
http://localhost/api.php?order_id=101

You will get the output as given below:
![](https://i.imgur.com/BMeg0bF.png)

This is how you can create REST API in PHP.

#### 7. What is PDO in PHP?
* PDO stands for PHP Data Object. PDO is a set of PHP extensions that provide a core PDO class and database, specific drivers. 
* The PDO extension can access any database which is written for PDO driver. There are several PDO drivers available which are used for FreeTDS, Microsoft SQL Server, IBM DB2, Sybase, Oracle Call Interface, Firebird/Interbase 6 and PostgreSQL databases etc.
* It gives a  lightweight, vendor-neutral, data-access abstraction layer. Hence, no matter what database we use, the function to issue queries and fetch data will be same. 
* It focuses on data access abstraction instead of database abstraction.

#### 8. Differentiate between GET and POST.
| GET | POST | 
| -------- | -------- | 
| GET method is used for requesting data from a specified resource.| POST is used for sending the data to the server as a package in a separate communication with the processing script.|
| Data is sent in the form of URL parameters which are strings of name-value pairs separated by ampersands(&). | Data sent through POST method will not be seen in the URL.|
| GET method cannot be used for sending binary data like images or word documents.| POST method can be used to send ASCII as well as binary data like images and word documents. |
| This method must not be used if you have any sensitive information like password to be sent to the server.| Sensitive information can be sent using this method.|
|It can be used for submitting the form where the user can bookmark the result.|Submissions by form with POST cannot be bookmarked. |
|  You can use this method only for data that is not secure. | Data sent through this method is secure.|
| GET method is not safer since parameters may be stored in web server logs or browser history. |POST method is a safer than GET because the parameters are not stored in web server logs or browser history.|

#### 9. Explain type hinting in PHP.
* In PHP, type hinting is used to specify the expected data type (arrays, objects, interface etc.) for an argument in function declaration. It was introduced in PHP 5.
* Whenever the function is called, PHP checks if the arguments are of user preferred type or not. If the argument is not of the specified type, the run time will display an error and the program will not execute.
* It is helpful in better code organization and improved error messages.
* Example usage:
    ```
    //sendEmail() function argument $email is type hinted of Email Class. It means to call this function you must have to pass an email object otherwise an error is generated.
    <?php
        function sendEmail (Email $email)
        {
          $email->send();
        }
    ?>
    ```

#### 10.  How to terminate the execution of a script in PHP ?
* To terminate the execution of script in PHP, `exit()` function is used. It is an built-in function which outputs a message and then terminates the current script. 
* The message which you want to display is passed as a parameter to the `exit()` function. Script termination will be done by this function  after displaying the message. It is an alias of die() function. It doesn’t return any value.
* Syntax: `exit(message)`
 Where message is a parameter to be passed as an argument. It defines message or status.
* Example: The code given below will print a message and exit the current script.
```
<?php
$site = "https://www.interviewbit.com//";
fopen($site,"r")
or exit("Unable to connect to $site");
?>
```

### Conclusion
PHP proves to be a great tool for writing dynamic web pages. It is not restricted to use by professional web developers. Non-technical users can also easily learn a few handy tricks to make their web pages easier to manage thereby making it more useful.

### References
* "PHP: A Beginner’s Guide" by Vikram Vaswani.
* "PHP & MySQL Web Development" by Luke Welling & Laura Thompson.
* https://www.w3schools.com/php/default.asp
* https://www.tutorialspoint.com/php/index.htm
* https://www.codecademy.com/learn/learn-php
* https://www.guru99.com/php-tutorials.html
* https://www.javatpoint.com/php-tutorial

### Multiple choice questions
#### 1. What is the name of scripting engine in PHP?
- [ ] a. SpiderMonkey
- [x] b. Zend Engine
- [ ] c. VBScript
- [ ] d. CS-Script
- Answer: b. Zend Engine

#### 2. Default file extension of php file is _______.
- [ ] a. .html
- [ ] b. .xml
- [ ] c. .hphp
- [x] d. .php
- Answer: d. .php

#### 3. Which of the following is the correct syntax of php?
- [x] a. `<?php ?>`
- [ ] b. `<?php >`
- [ ] c. `?php ?`
- [ ] d. `<php >`
- Answer: a. `<?php ?>`

#### 4. Can PHP send and receive cookies?
- [x] a. True
- [ ] b. False
- [ ] c. PHP new version can not send and receive cookies but old version can.
- [ ] d. PHP older version can not send and receive cookies but new version can.
- Answer: a. True

#### 5. PHP runs on which platform?
- [ ] a. Linux
- [ ] b. Mac OS X
- [ ] c. Windows
- [x] d.  All of the above
- Answer: d.  All of the above

#### 6. Does PHP support multiple inheritance?
- [ ] a. Yes
- [x] b. No
- [ ] c. Single and multiple inheritance is supported.
- [ ] d. Single and multilevel inheritance is supported.
- Answer: b. No

#### 7. Which programming language does PHP resemble to?
- [ ] a. JavaScript
- [ ] b. VBScript
- [x] c. Perl and C
- [ ] d. All of the above
- Answer: c. Perl and C

#### 8. What is the output of PHP code given below?
```
<?php
$x = 8;
$y = 8.0;
echo ($x === $y);
?>
```
- [x] a. No output
- [ ] b. 8 === 8
- [ ] c. 0
- [ ] d. 1
- Answer: a. No output
- Explanation: x is of type int and y is of type float. So there is no output due to type mismatch.

#### 9. Which method sends input to a script via a URL?
- [x] a. GET
- [ ] b. POST
- [ ] c. Both
- [ ] d. None
- Answer: a. GET

#### 10. PHP is an example of _______ scripting language.
- [ ] a. Browser-side
- [ ] b. Client-side
- [x] c. Server-side
- [ ] d. In-side
- Answer: c. Server-side

#### 11. _______ variable is not a predefined variable.
- [ ] a. `$GET` 
- [ ] b. `$POST`
- [x] c. `$ASK`
- [ ] d. `$REQUEST`
- Answer: c. `$ASK`

#### 12. ______ symbol is a newline character.
- [x] a.`\n`
- [ ] b. `\r`
- [ ] c. `/n`
- [ ] d. `/r`
- Answer: a. `\n`

#### 13. Variables always start with a _____ in PHP.
- [ ] a. Euro-sign
- [ ] b. Pond-sign
- [ ] c. Yen-sign
- [x] d. Dollar-sign
- Answer: d. Dollar-sign 

#### 14. Which function is used for testing the  type of PHP variable?
- [ ] a. `whattype()`
- [ ] b. `showtype()`
- [x] c. `gettype()`
- [ ] d. `settype()`
- Answer: c. `gettype()` 

