PHP interview questions

Want to become an expert in cracking PHP interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public PHP interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. FileOwners
PHP Language Public

Implement a groupByOwners function that:

  • Accepts an associative array containing the file owner name for each file name.
  • Returns an associative array containing an array of file names for each owner name, in any order.

For example, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"] the groupByOwners function should return ["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]].

Easy  
10min
Solve question

2. Palindrome
PHP Strings Public

A palindrome is a word that reads the same backward or forward.

Write a function that checks if a given word is a palindrome. Character case should be ignored.

For example, isPalindrome("Deleveled") should return true as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.

Easy  
10min
Solve question

3. Path
PHP Data structures Strings Public

Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example:

$path = new Path('/a/b/c/d');
echo $path->cd('../x')->currentPath;

should display '/a/b/c/x'.

Note: Do not use built-in path-related functions.

Hard  
30min
Solve question

4. Thesaurus
PHP Serialization Public

A thesaurus contains words and synonyms for each word. Below is an example of a data structure that defines a thesaurus:

array("buy" => array("purchase"), "big" => array("great", "large"))

Implement the function getSynonyms, which accepts a word as a string and returns all synonyms for that word in JSON format, as in the example below.

For example, the call $thesaurus->getSynonyms("big") should return:

'{"word":"big","synonyms":["great", "large"]}'

while a call with a word that doesn't have synonyms, like $thesaurus->getSynonyms("agelast") should return:

'{"word":"agelast","synonyms":[]}'
Hard  
10min
Solve question

If you feel ready, take one of our timed public PHP interview questions tests:

  • HTML/CSS, JavaScript, PHP, and SQL online test (Easy / Hard)
  • PHP online test (Easy / Hard)
  • PHP and SQL online test (Easy / Hard)
  • PHP and WordPress online test (Easy / Hard)
Not exactly what you are looking for? Go to our For developers section.