PHP Interview Questions & Answers for Freshers

Are you a looking for PHP Interview Questions for Freshers? Find PHP Interview Questions and Answers for beginners here. It is important to learn basic PHP concepts while doing PHP Job Preparation. These are the commonly asked Interview questions for beginners.

What are the different types of error in PHP?

There are four basic types of run-time errors in PHP:

  1. Notices
  2. Warnings
  3. Fatal Error
  4. Parse Errors:

For more detail, please check PHP Errors

PHP’s numerically indexed array begin with which position?

PHP Indexed array begins with position 0.
For example if: $array=array(15,80,67,33); Then these elements will have following positions:
$array[0]=10 (This is beginning position 0 not 1)

Which PHP function inserts an element to the end of an array?

PHP array_push() function is used to insert one or more elements to the end of an array.

Why we use PHP String functions trim(), ltrim() and rtrim()?

PHP trim related functions are used to remove white spaces or other given characters from the beginning and end of the strings.

  • trim() removes space & predefined characters from both sides of given string.
  • ltrim() removes space & predefined characters from the left side of the sting.
  • rtrim() removes space & predefined characters from the right side of the sting.

These functions are helpful when we want to clean strings from unwanted spaces or characters.

Syntax: trim(string,charlist)


Which PHP function can be used check if variable is an array?

PHP is_array() function is used to check, if a variable is an array or not. This is_array() function will return true, if a variable is an array or false if it is not.

What PHP Function is used to find position of a string?

PHP strpos() function is used to find the first occurrence of substring in the given string.

Output: 13

The word ‘apple’ is found at the position ’13’. Remember that the position of string/character start at 0, and not 1. This function is very useful to find certain patterns or words in a string.

How many types of arrays are available in PHP?

There are three types of array available in PHP.

  1. Numeric (Indexed) array
  2. Associative array
  3. Multidimensional array

Learn more about array with examples in PHP Array Tutorial

What is the use of ucwords() PHP String function?

PHP ucwords() function is used to capitalized the first letter of each word in String.

Run :

What is the use of array_chunk() function in PHP?

The array_chunk() function is used to split an array into parts or chunks of new arrays. Example: array_chunk(array,size);

The first parameter specifies an array and the second parameter defines the size of each chunk.

What is the use of str_replace() PHP String function?

The PHP str_replace() function is used to search & replace some words in a strings.

In this example, “Hello” word will be replaced by “Hi” in the given string.

Run :