Basic PHP Interview Questions?

1) What is PHP? 

  • PHP is a server-side scripting language that is basically used for developing dynamic web pages. 

2) What is the difference between echo( ) and print ( )?

  • echo and print are more or less the same. They are both used to output data to the screen.The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters while print can take one argument. echo is marginally faster than print. 

3) What is print_r( )?

  • This is also an output function used in PHP, It is used to display the whole array in PHP. 

4) How to include files in PHP?

  • We can include a file using "include( )" or "require( )" function with file path as its parameter.

5) What is the difference between GET and POST?

  • We can send small data using GET method but POST method can transfer a large amount of data and POST is secure method than GET method. 

7) How to declare an array in PHP?

  • $arr = array('apple','grape','lemon); 

8) What is the use of in_array( ) in PHP?

  • in_array used to checks if a value exists in an array. 

9) What is the use of count( ) function in PHP? 

  • count( ) is used to count all elements in an array or something in an object.

10) What is the difference between include and require?

  • By using both two functions we include the file in the PHP program, How they handle the failures, If the file is not found by require ( ), it will cause a fatal error and halt the execution of the script. If the file is not found by include( ), a warning will be issued, but execution will continue.

11) What is the difference between Session & Cookie? 

  • The main difference between sessions and cookies is that the session is stored on the server and cookies are stored on the user's computers in text file format. Cookies can not hold multiple variables but the session can hold multiple variables, But Session can hold multiple variables. We can set expiry for a cookie, The session remains active as long as the browser is open. 

12) How to set cookies in PHP?

  • setcookie("sample",time()+3600); 

13) How to retrieve a Cookie value?

  • echo $_COOKIE['user']; 

14) How to create a session? How to set a value in session? How to remove data from a session? 

  • Create session: session_start( );
  • Set value into session: $_SESSION['USER']=1; 
  • unset($_SESSION['USER']);

Comments

Popular posts from this blog

Basic Terminology

What is normalization in DBMS?

Object oriented programming concepts in PHP