PHP Interview Questions and Answers for Fresher Level Candidates

PHP Interview Questions and Answers for Fresher Level Candidates

  • PHP
  • 7 mins read

The following is top 45 PHP interview questions and answers which are suitable for fresher level candidates.

1)What is PHP?
Answer: PHP is a server-side scripting language used for web development.

2)Why PHP differs from other languages?
Answer: PHP is easy to learn and easy to understand, and it can run on many platforms such as Windows, Linux, Unix, etc. and supports a broad range of databases.

3)Why is PHP called as a Server-side scripting language?
Answer: PHP supports script that runs mostly on a server.

4)Who is the father of PHP?
Answer: Rasmus Lerdorf

5)What is the old name of PHP?
Answer: Personal Home page

6)What is the difference between PHP and JAVA?
Answer: PHP is a server-side scripting language where JAVA is a server-side and desktop programming language.

7)Is PHP a compiled or Interpreted language?
Answer: PHP is an interpreted language. But for some time we can use it as a compiled language.

8)Is PHP a case sensitive language?
Answer: Variable names in PHP are case sensitive, but function names are not case sensitive.

9)What is the default extension of a PHP file?
Answer: .php.

10)What is variable in PHP?
Answer: Variable is a storage location to store a data value. It is temporary storage.

11)What are the different types of variables in PHP?
Answer: Integers, Doubles, Booleans, NULL, Strings, Arrays, Objects, Resources.

12)What is the local variable?
Answer: Local variable is a variable which is defining inside a function, and it is accessible within that function only.

13)What is a global variable?
Answer: Global variable is a variable which is defining outside a function and is available to access outside that function.

14)What is a Static variable?
Answer: Static variable is a variable which is defining inside a function using the keyword static and can be accessible outside the function. After the execution of that function, the static variable can be available also.

15)What is the difference between local and static variable?
Answer: Local variable is deleted after the execution of a function, which contains that variable. But the static variable is not removed after the execution of a function because of static keyword.

16)What is the difference between $a and $$a?
Answer: $a is a storage location to store a fixed data value while $$a is using to store a variable of variables and data which is containing by $$a can change dynamically.

17)What is an operator in PHP?
Answer: An operator is a symbol which can contain one or more operands and operate on them to produce a result.

18)What is the difference between += and .= in PHP?
Answer: += is the numeric operator used for addition of numbers and .= is a string operator used for string concatenation.

19)What is the difference between ++$a and $a++?
Answer: ++$a is pre-increment operation that increases $a by 1 and then returns the value while $a++ is the post-increment operation that firstly returns the value of $a and then increases the value by 1.

20)What is the associativity of operators in PHP?
Answer: Associativity is the order where operators of the same precedence evaluate.

21)What is the precedence of operators in PHP?
Answer: Precedence is the order in which they evaluate.

22)What is the difference between = and == in PHP?
Answer: = is the assignment operator who is using to assign a value to a variable. Where == is the comparison operator who is using to compare values between two variables and returns true based on the comparison.

23)What is the difference between == and === in PHP?
Answer: Both == and === are comparison operators. == operator is using to check where the values of two operands are equal or not and === is using to check the values for equality of the same type of operands.

24)What is the echo in PHP?
Answer: echo() is using to print one or more strings to the console or the web browser.

25)What is the loop in PHP?
Answer: The loop is a repeated execution of a block of statements until a condition meets.

26)How many types of loops are in PHP?
Answer: 4 types.for loop,while loop,do-while loop,foreach loop

27)What is the difference between for and do-while loop in PHP?
Answer: While loop executes a block of codes until a condition is false. But do-while loop runs codes once, and it checks a condition, and if the condition is true then loop body executes again, this process continues until the condition becomes false.

28)What is an array in PHP?
Answer: Array is a particular type of variable that can hold more than one element at a time.

29)How many types of arrays in PHP?
Answer: Three types. (i)Indexed array, (ii)Associative array, (iii)Multidimensional array.

30)What is Indexed Array in PHP?
Answer: Indexed array is an array which can hold elements in an indexed form that is specifying by numbers starting from 0 with incrementing by 1.

31)What is Associative array in PHP?
Answer: It is an array that can hold elements with a string index.

32)How will return the number of elements from an array in PHP?
Answer: count() function is using to return the number of elements from an array.

33)What is a multidimensional array?
Answer: Multidimensional array is an array which contains one more array.

34)How will return the length of a string in PHP?
Answer: strlen() is using to return the length of a string.

35)What is the difference between strtoupper() and strtolower() in PHP?
Answer: strtoupper() is using to return a string in uppercase while strtolower() is using to return a string in lowercase.

36)What is the difference between strcmp() and strcasecmp() in PHP?
Answer: strcmp() is a case-sensitive comparison function on strings and strcasecmp() is a case-insensitive comparison function on strings.

37)what is the difference between chr() and ord() in PHP?
Answer: chr() is using to convert an ASCII value to a character while ord() is using to return the ASCII value of the first character of a string.

38)What is the difference between trim(), ltrim(), rtrim() in PHP?
Answer: trim() is using to remove spaces and predefined characters from both sides of a given string, ltrim() is using to remove spaces, and present characters from the left side of a string, rtrim() is using to remove spaces and predefined characters from the right side of a given string.

39)What is the difference between ucfirst() and ucwords() in PHP?
Answer: ucfirst() is using to return a string with the first letter in uppercase while ucwords() is using to return a string with a first capitalized letter of each word.

40)What is the difference between asort() and sort() in PHP?
Answer: sort() is using to sort an array in ascending order while asort() is using to sort an associative array according to value.

41)What is the difference between rsort() and arsort() in PHP?
Answer: rsort() is using to sort an array in descending order while arsort() is using to sort an associative array in descending order according to value.

42)What is the difference between ksort() and krsort() in PHP?
Answer: ksort() is using to sort an associative array in ascending order according to the key while krsort() in PHP is using to sort an associative array in descending order according to the key.

43)What is the difference between strpos() and strrpos() in PHP?
Answer: strpos() is using to find the position of the first occurrence of a string inside another string while strrpos() is using to detect the location of the last occurrence of a string inside another string.

44)What is the difference between strlen() and count() in PHP?
Answer: strlen() is using to return the length of characters from a string while count() is using to return the number of elements of an array.

45)What is difference between strpos() and stripos() in PHP?
Answer: strpos() and stripos() are using for finding the position of the first occurrence of a string inside another string. But strpos() is case-sensitive and stripos() is case-insensitive.

See also:

Top 50 PHP Interview Questions and Answers