Php interview questions answers
Php interview questions answers

100+ PHP Interview Questions and Answers

We provide the important php interview questions and answers for freshers and experience. Technical and logical Php interview questions answers.

1. What is PHP?

PHP stands for “Hypertext Preprocessor”. PHP is a server-side scripting language. It is a powerful tool for making dynamic and interactive Web pages. Php is an interpreted language. It is also an object oriented programming language like java, C-sharp etc.

2. Who is known as the father of PHP?

Rasmus Lerdorf.

3. What was the old name of PHP?

Personal Home Page.

4. What is the name of scripting engine in PHP?

The scripting engine that powers PHP is called Zend Engine 2.

5. Explain the difference between PHP4 and PHP5.

PHP4 doesn’t support oops concept and uses Zend Engine 1.

PHP5 supports oops concept and uses Zend Engine 2.

6. List some of the features of PHP7.

  • Scalar type declarations
  • Return type declarations
  • Null coalescing operator (??)
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Closure::call method
  • Group use declaration
  • Generator return expressions
  • Generator delegation
  • Space ship operator

7. What is the difference between $message and $$message?

  • $message stores variable data while $$message is used to store variable of variables.
  • $message stores fixed data whereas the data stored in $$message may be changed dynamically.

8. What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries.

It also provides a command line interface to install “packages” automatically.

9. How do you execute a PHP script from the command line?

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows:

php script.php

10. How to run the interactive PHP shell from the command line interface?

Just use the PHP CLI program with the option -a as follows:

php -a

11. What are the popular Content Management Systems (CMS) in PHP?

  • WordPress
  • Joomla
  • Magento
  • Drupal etc.

12. Difference b/w static and dynamic websites?

In static websites, content can’t be changed after running the script. You can’t change anything in the site. It is predefined.

In dynamic websites, a content of script can be changed at the runtime. Its content is regenerated every time a user visit or reload. Google, Yahoo, and every search engine is the example of a dynamic website.

13. What are the popular frameworks in PHP?

  • CakePHP
  • CodeIgniter
  • Yii 2
  • Symfony
  • Zend Framework etc.

14. Which programming language does PHP resemble?

PHP has borrowed its syntax from Perl and C.

15. What is “echo” in PHP?

PHP echo output one or more string. It is a language construct not a function. So the use of parentheses is not required. But if you want to pass more than one parameter to echo, use of parentheses is required.

The echo statement can be used with or without parentheses: echo or echo()

16. What is “print” in PHP?

PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.

The print statement can be used with or without parentheses: print or print().

17. What is the difference between “echo” and “print” in PHP?

Echo can output one or more string but print can only output one string and always returns 1.

Echo is faster than print because it does not return any value.

18. How is a variable declared in PHP?

PHP variable is a name of a memory location that holds data. It is a temporary storage.

In PHP, a variable is declared using $ sign followed by a variable name.

Syntax of declaring a variable in PHP is given below:

$variablename=value;
$str="hello string";  
$x=200;  
$y=44.6;  
echo "string is: $str <br/>";  
echo "integer is: $x <br/>";  
echo "float is: $y <br/>";  
?>

19. Explain PHP variable length argument function

PHP supports variable length argument function. It means you can pass 0, 1 or n number of arguments in the function. To do this, you need to use 3 ellipses (dots) before the argument name. The 3 dot concept is implemented for variable length argument since PHP 5.6.

20. Explain the PHP variable length argument function.

PHP supports variable length argument function. It means you can pass 0, 1 or n number of arguments.

21. What is the array in PHP?

Array is used to store multiple values in a single value. In PHP, it orders maps of pairs of keys and values. It stores the collection of a data type.

22. How many types of the array are there in PHP?

There are three types of the array in PHP:

  • Indexed array
  • Associative array
  • Multidimensional array

23. Explain some of the PHP array functions?

There are many array functions in PHP:

  • array()
  • array_change_key_case()
  • array_chunk()
  • count()
  • sort()
  • array_reverse()
  • array_search()
  • array_intersect()

24. What is the difference between indexed and associative array?

The indexed array holds elements in an indexed form which is represented by number starting from 0 and incremented by 1. For example:

$season=array("summer","winter","spring","autumn");

The associative array holds elements with name. For example:

$salary=array("Sonoo"=>"350000","John"=>"450000","Kartik"=>"200000");

25. How to get the length of string?

The strlen() function is used to get the length of a string.

26. Explain some of the PHP string functions?

There are many array functions in PHP:

  • strtolower()
  • strtoupper()
  • ucfirst()
  • lcfirst()
  • ucwords()
  • strrev()
  • strlen() etc.

27. What are the ways to define a constant in PHP?

PHP constants are name or identifier that can’t be changed during execution of the script. PHP constants are defined in two ways:

  • Using define() function
  • Using const() function

28. What are magic constants in PHP?

PHP magic constants are predefined constants which change on the basis of their use. They start with a double underscore (__) and end with a double underscore (__).

29. How many data types are there in PHP?

PHP data types are used to hold different types of data or values. There are 8 primitive data types which are further categorized into 3 types:

  • Scalar types
  • Compound types
  • Special types

30. How to do single and multi-line comment in PHP?

PHP single line comment is done in two ways:

Using // (C++ style single line comment)
Using # (Unix Shell style single line comment)
PHP multi-line comment is done by enclosing all lines within /* */.

31. What are the different loops in PHP?

For, while, do-while and for each.

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

The PHP count() function is used to count total elements in the array, or something an object.

33. What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this function.

34. What does isset() function?

The isset() function checks if the variable is defined and not null.

35. Explain PHP parameterized functions.

PHP parameterized functions are functions with parameters. You can pass any number of parameters inside a function. These passed parameters act as variables inside your function. They are specified inside the parentheses, after the function name. Output depends upon dynamic values passed as parameters into the function.

Leave a Reply