Loading...

The Free Online Tutorials, and Always will be.

PHP Interview Questions

What is php ?


Php is a very popular server side scripting language used for creating dynamic websites for web development. it stands for Hypertext Preprocessor.

What is the difference between static webistes vs dynamic websites ?


Static website are those in which the content remains unchanged on the web page. every time the user visits that page the content remains same.
these websites are used only for showing information to the user that not changes over time. In static websites user can't query the website.
whereas Dynamic website are those in which the content changes every time the user visits that page based on user queries or user interaction.
for example in google.com google result page shows different page content based on the user query.
which means dynamic website have the live interactivity with the user . whereas static websites does not have the live interactivity.
for example facebook.com have live interactivity with the user. in which user can send messages, friend requests .
whereas in case of static website the example is wikipedea in which user only read information and can not interact with that.

which programming languages does php resemble to ?


php resembles c, perl

What is the difference between $msg and $$msg ?


'$' is used in php for variable declaration to store a value in it just like string, int etc.
whereas '$$' is used in php for reference variable declaration. means it is used to store value of variable in it.
for example :-

php code
                		     					    		
<?php 
$msg = "student";
$$msg = "how are you ?";
echo $msg."<br/>";
echo $$msg."<br/>";
echo $student."<br/>";
?>
                		     					        	
                		     					        
output :
student
how are you ?
how are you ?

means in reference variable "$$msg"
it assigns $msg value i.e student in place of $'$msg = "student"' => $student.

what is 'echo' and 'print' in php ? ?


'echo' is much faster than 'print'.
in 'print' we can print arrays as a whole but in echo we can't.
echo doesn't return any value whereas print return value of 1. echo can output one or more string values but in print we can get output of one string.

In how many ways we can define constants in php ? ?


By two ways :
1. by using const keyword
2. by using define() method
the conventions used for constants in any programming language is to used in all uppercase letters in the constant name. for example :
-> const HOST = "localhost";
-> define(constant_name, constant_value, case-insensitive )   //case sensitive is default in php
for example :
define("HOST", "localhost", case-insensitive);

why we use isset() function in php ?


the isset() function in php is used for check the condition i.e variable is defined or set and it should not be null.
it returns false if the defined variable is NULL.

why we use empty() function in php ?


the empty() function is used to check the condition i.e the variable is empty or NULL.
it returns true if the variable is empty or having a NULL value otherwise returns false.

what is the array in php ?


an array in php is used to store similar type of values in a single variable.
for example :
$week = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturdar");
in $weak is a single variable which holds similar values in it.

How to know the length of the given string ?


the strlen() function is used to know the length of the given string.
for example :
        		     					    		
<php
$msg = "iphone 11 launches on 10th september 2019";
echo "the length of the string is :".strlen($msg);
?>
output:
the length of the string is :41

What are the methods to submit form in PHP ?


Php has two inbuilt methods to handle the form submission are : GET and POST.

In Php how we get the form data for processing ?


Php has two inbuilt superglobal variables to get the form data are : $_GET and $_POST.
$_GET and $_POST are two superglobal arrays which hold the all form data in these variables.

What is the difference b/w unset() and unlink() in php ?


the unset() function is used in php to uninitialize a already defined variable or file in php
if the variable or file is defined or have any data in it . then it empty that variable or file for which it is used.
for example :
        		     					    		
<?php
$msg = "hello";
echo $msg."<br/>";
unset($msg);
echo $msg."<br/>";
?>
Output:
     //it will show nothing because the variable is empty now
the unlink() function is used to delete a file or file path from the server completely. it returns 1 if the file deleted otherwise 0.
for example:
        		     					    		
<?php
$file = "index.html";
unlink($file);
?>
Output :
1

default session time in php ?


the default session time used in php is 1440 seconds which means 24 minutes.

What is cURL in php ?


the cUrl (client URL) is a library in php. which enables to make http requests via URL easily in php.
in simple it allows to send and receive information via URL.

What is the use of implode() and explode() in php ?


the implode() function is used in php to convert the values of an array into a string by using a delimeter. for example :
        		     					    		
<?php
$chars = array("ram","ghanshyam","sitaram","dayaram");
$msg = implode(" ", $chars);
echo $msg;
?>        		     					    			
        		     					    		
        		     					    	
Output :
ram ghanshyam sitaram dayaram
the explode() function works as the opposite of implode(). it makes a string value into array values based on delimeter.
in simple means it converts a string into array.
for example :
        		     					    		
<?php
$chars = "ram ghanshyam sitaram dayaram";
$msg = explode(" ", $chars);
print_r($msg);
?>        		     					    			
        		     					    		
        		     					    	
Output :
Array ( [0] => ram [1] => ghanshyam [2] => sitaram [3] => dayaram )

Difference b/w "==" and "===" in php ?


the "==" is the equality operator in php which is used to check values of both left and right side variables is equal.
for example :
        		     					    		
<?php
   $var1 = "11" ;
   $var2 = 11;
   if($var1 == $var2){
     echo "var1 and var2 are equal";
   }
   else{
     echo "var1 and var2 are not equal";
   }
   //print var1 and var2 are equal. because php check type values at run time 
?>        		     					    			
        		     					    		
        		     					    	
Output :
var1 and var2 are equal
whereas "===" is used in php to check two variables are equal and are of the same data type.
for example :
        		     					    		
<?php
   $var1 = "11" ;
   $var2 = 11;
   if($var1 === $var2){
     echo "var1 and var2 are equal";
   }
   else{
     echo "var1 and var2 are not equal"
   }
   /*
     print var1 and var2 are not equal. 
     because "11" is treated as string for use of quotes around.
     and 11 is of number type because it doesn't have quotes around.  
   */      
?>        		     					    			
        		     					    		
        		     					    	
Output :
var1 and var2 are not equal

Difference b/w include() and include_once() in php ?


both the include() and include_once is used in php to include a file in php script. if file doesn't found then php script shows the warning and continues the script execution.
for using a specific file which needs in php for some specific task then we used include() for that file. but, if we use include() for a same file again and again then it will include that file multiple times.
whereas if there is a situation we have the same file , but we have include it more than one time then, include_once() is used for not include that file again and again. it includes that file only one time and if php finds that file include more than one time. then php ignores that file.

Difference b/w require() and require_once() ?


require() is used to include a file in the php page that is necessary for php script to execute. if file not include by using require() then php shows fatal error and script stops the execution.
whereas require_once() works as same require() except that if there is multiple instance of the same file include in php it will not include it again.