PHP Interview Questions
1 .
What is list in PHP?
The list is similar to an array but it is not a function, instead, it is a language construct. This is used for the assignment of a list of variables in one operation. If you are using PHP 5 version, then the list values start from a rightmost parameter, and if you are using PHP 7 version, then your list starts with a left-most parameter. Code is like:

<?php
  $info = array('red', 'sign', 'danger');
  // Listing all the variables
  list($color, $symbol, $fear) = $info;
  echo "$color is $symbol of $fear”
?>‚Äč
2 .
What is MIME?
MIME stands for Multipurpose Internet Mail Extensions is an extension of the email protocol. It supports exchanging of various data files such as audio, video, application programs, and many others on the internet. It can also handle ASCII texts and Simple Mail Transport Protocol on the internet.
3 .
How can you get the size of an image in PHP?
getimagesize() function is used to get the size of an image in PHP. This function takes the path of file with name as an argument and returns the dimensions of an image with the file type and height/width.

Syntax:
array getimagesize( $filename, $image_info )
4 .
What is the difference between nowdoc and heredoc?
Heredoc and nowdoc are the methods to define the string in PHP in different ways.
 
* Heredoc process the $variable and special character while nowdoc doesn't do the same.

* Heredoc string uses double quotes " " while nowdoc string uses single quote ' '

* Parsing is done in heredoc but not in nowdoc.
5 .
What is difference between md5 and SHA256?
Both MD5 and SHA256 are used as hashing algorithms. They take an input file and generate an output which can be of 256/128-bit size. This output represents a checksum or hash value. As, collisions are very rare between hash values, so no encryption takes place.
 
* The difference between MD5 and SHA256 is that the former takes less time to calculate than later one.
* SHA256 is difficult to handle than MD5 because of its size.
* SHA256 is less secure than MD5
* MD5 result in an output of 128 bits whereas SHA256 result output of 256 bits.

Concluding all points, it will be better to use MDA5 if you want to secure your files otherwise you can use SHA256.
6 .
How would you connect to a MySQL database from a PHP script?
To connect to some MySQL database, the mysqli_connect() function is used. It is used in the following way :
<?php 
  $database = mysqli_connect("HOST", "USER_NAME", "PASSWORD");
   mysqli_select_db($database,"DATABASE_NAME"); 
?>
7 .
What are the differences between mysqli_connect and mysqli_pconnect?
mysqli_pconnect() function is used for making a persistent connection with the database that does not terminate when the script ends.
 
mysqli_connect() function searches any existing persistence connection first and if no persistence connection exists, then it will create a new database connection and terminate the connection at the end of the script.
 
Example :
$DBconnection = mysqli_connect("localhost","username","password","dbname");
// Check for valid connection
if (mysqli_connect_errno())
{
echo "Unable to connect with MySQL: " . mysqli_connect_error();
}
 
mysqli_pconnect() function is depreciated in the new version of PHP, but you can create a persistence connection using mysqli_connect with the prefix p.
8 .
Which function you can use in PHP to open a file for reading or writing or for both?
You can use fopen() function to read or write or for doing both in PHP.
 
Example :
$file1 = fopen("myfile1.txt","r"); //Open for reading
$file2 = fopen("myfile2.txt","w"); //Open for writing
$file3 = fopen("myfile3.txt","r+"); //Open for reading and writing
9 .
Which function is used in PHP to search a particular value in an array?
in_array() function is used to search a particular value in an array.
 
Example :
$languages = array("HTML", "CSS", "ANGULAR", "C", "Java", "PHP", "VB.Net");
if (in_array("PHP", $languages)) {
echo "PHP is in the list";
}
else {
echo "php is not in the list";
}
10 .
What is the use of mysqli_real_escape_string() function?
mysqli_real_escape_string() function is used to escape special characters from the string for using a SQL statement
 
Example :
$DBconnection=mysqli_connect("localhost","username","password","dbname");
$productName = mysqli_real_escape_string($con, $_POST['proname']);
$ProductType = mysqli_real_escape_string($con, $_POST['protype']);