Contact us

Top PHP Interview Questions and Answers for Beginners in 2021

Q.1 What is PHP.

PHP is a server side programming language. It is used in web development. Dynamic websites and web applications are created using it. Dynamic websites are websites in which information changes automatically. Through this programming language, programs are created and run on server computers

that change the information contained within the web sites. How the information will appear in the website depends / depends on the logic of the program. Programming can be done in PHP in both ways procedural and OOP.  

Q.2 What is the full form of PHP.

PHP Full form - Hypertext Preprocessor.

 

Q.3 How many types of data types are there in PHP.

There are 9 types of data types in PHP: - 

  1. Scalar Type - Scalar type is a data type that can store only one value. Examples of this are: - integer, float, boolean, string.
  2. Compound Type - Compound is a type that can store more than one value. Examples of this are: - array, object, callable.
  3. Special Type - resource, null.

 

Q.4  What is a variable.

Variable (variable) is the name of a memory location in which data is stored. 

 

Q.5  How to define a block of PHP Script.  

Script Block = <?Php    Code goes here...       ?>. The code of php is written inside this block. 

 

Q.6  What is an Array. 

Array is a data type that is used to store more than one data values sequentially in computer memory.

 

Q.7  How to 9declare and define Array in PHP.

Method of defining array - $ arr = array ('Green', 'Yellow', 'Red');                                                         The array () is a function that create and returns an Array. In Array, more than one value can be stored at a time, as seen in the code above, three values have been stored together with 'Green', 'Yellow', 'Red'.   

 

Q.8 How many types of main errors does PHP have. 

There are three types of main errors: -  Notices, Fatal, Error.

 

Q.9 How many types of arrays are there in PHP? 

There are two types of arrays in PHP: - 1) indexed Array and 2) Associated Array                                     In an indexed array index-number of values is automatically formed. Lets take an example.      

                      $arr  = array(5, 7, 'hello', 4.5); 

The index of first value 5 in this Array is 0 of , index of 2nd value 7 is 1 , index of 'hello' is 2, index of 4.5 is 3, etc.   

In Associative Array indices of values can be defined manually. Let us understand by example: -

                  $arr  = array('first' => 5, 'second' => 7, 'third' => 'hello', 'fourth' => 4.5);

In this array, first element has index of 5, index of 7 is second, index of 'hello' is third etc. The index in Associative Array can be both numeric and string. 

 

Q.10  what does echo do.

Whatever is written after the echo keyword it gets printed in the screen of computer and browser.  

 

Q.11 What is a function How to create and define a function in PHP. 

Function is a block of code that is written once, then the same code block is used repeatedly in the program. In this way, it is avoided to write the same code again and again. 

 

Q.12 How to include another PHP file in a PHP file. 

include('filename') और require('filename').   File can be included by both these functions. Parameters of both functions are the name of the file to be included.           

 

Q.13 What is the difference between include() and require(). 

Both functions include the file in the PHP page, but if there is an error in the php file written inside in require() then the code of php stops running and the Fatal Error message is displayed on the screen while in include() If there is any error in the file written inside the include(), then the code of php keeps running, only the warning message is displayed on the screen.    

 

Q.14 What is the difference between include_once() and require_once().

The function of include_once() is similar to that of include(), the only difference is that the include_once() function checks if the files being included are not already included or not. If not then only file is included. | Similarly the require_once () function also acts like require (), as well as ensures that the file is included only once.   


Q.15 How many types of Loop exist in PHP? 

There are four main types of loops in PHP: - for, while, do while, foreach. 


Q.16 Write a program using Loop. 


<?php

                   $x = 1;
                   while($x < 5 )
                  {
                      echo "The Number is ". $x . "<br>";
                     $x++;
                  }
?>

The output of this code will be: -  

                        1
                        2
                        3
                        4

 

Q.17 == and === . What is the difference between these two operators.

Both operators check whether the variables are equal or not. But there is some difference between the two. == It checks whether the values of two variables are same or not. Returns true if it is the same, if it is not equal then returns false. === This operator checks the value of the variables and also checks whether the two variables are of the same type. If both value and type are same then it return true otherwise false.

 

Q.18 What is the difference between GET and POST Request? 

The request is sent to the server by both GET and POST. But there is some difference between the two:- 

The amount of data can be sent to the server by GET is only 1024 bytes. While POST can send more data to the server. Whenever a request is sent through GET, all the data that goes to the server along with the request are visible in URL and can be seen in browser address bar. Conversely, when data is sent by POST, it does not append in url instead it is append in HTTP Request body, hence in POST request data cannot be displayed in browser screen.

 

Q.19  What is the difference between Session and Cookie?

Both Session and Cookie are methods used in web development. They are used to save user information. Session uses server while Cookie uses web browser. The data saved in session is stored in server, so no one can access the data in the session. While the cookie's data is stored in the browser itself, the data contained in the cookie can be accessed by any user. Session is used in techniques such as login and logout while Cookie is mostly used for user tracking.     

 

Q.20 What are the GLOBAL variables in PHP? 

PHP 4.1.0 version includes GLOABAL variable in PHP. GLOBAL variables are variables that are already built in PHP. We can access these variables from anywhere in our code. There is a lot of important information in these variables. Here are some GLOABAL variables: - All the global variables defined in the php file can also be accessed by an array named $ GLOABALS.  

  1. $ _SERVER - This array contains information related to the server such as server address, name, protocol etc. 
  2. $ _POST - This array contains the data that is sent by the client from the POST request. 
  3. $ _GET - This array contains the information that comes with the GET request. 
  4. $ _FILES - Whenever a file is uploaded by the client to the server, the information of the file is stored in the $ _FILES array. 
  5. $ _COOKIE - Contains data related to cookie $ _SESSION - This session contains the information of the session.  

1 Review:

यह पोस्ट आपको किसी लगी इसके बारे में लिखें