Developer Blog

  • Blog
  • /
  • Test Tasks for PHP Interviews that developers will enjoy solving.
By Dracony on 30 July 2013

My last post about some useful questions for a PHP interview got some attention so I decided to follow up with a few test tasks to give developers on an interview. I know some companies prefer to use them instead of questions saying that this way they can see some of the actual code and get some insight about how this particular developer approaches problem solving. Unfortunately a lot of people find these frustrating, since they they are usually time consuming and often quite boring and repetitive. Those that offer some challenge are usually deeply connected with math and therefore can be hard for people who have lots of experience in the actual web development but none in math or graph algorithms.

So here are some simple test tasks that I would suggest, I would say each of them takes under an hour to complete. I tried to make them feel new and so be more interesting to the developer who’ll be solving them.

1) Print an associative array as an ASCII table. E.g you have this array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
array(
    array(
        'Name' => 'Trixie',
        'Color' => 'Green',
        'Element' => 'Earth',
        'Likes' => 'Flowers'
        ),
    array(
        'Name' => 'Tinkerbell',
        'Element' => 'Air',
        'Likes' => 'Singning',
        'Color' => 'Blue'
        ),  
    array(
        'Element' => 'Water',
        'Likes' => 'Dancing',
        'Name' => 'Blum',
        'Color' => 'Pink'
        ),
);

And expect this output:

1
2
3
4
5
6
7
+------------+-------+---------+---------+
| Name | Color | Element | Likes |
+------------+-------+---------+---------+
| Trixie | Green | Earth | Flowers |
| Tinkerbell | Blue | Air | Singing |
| Blum | Pink | Water | Dancing |
+------------+-------+---------+---------+

The position of the elements in each subarray may vary but the keys themselves are always the same. Give extra points if the developer can make Color colum colored depending on the color name (of course you will have to specify a finite list of colors then) and if he substitues the names of the elemnts with the ASCII symbols of the elements.

Most PHP developers dont get much of a chance to work with ASCII interfaces but they see such tables a lot in MySQL for example so it might be interesting for them to try this out. Drawing such a table doesnt require any additional knowledge so it wont be that hard for anyone.

2) Split an array of numbers into a specified number of groups so that the sum of all elements in each group would be as equal as possible. E.g.

1
2
3
4
5
6
7
You have these numbers:
1,2,4,7,1,6,2,8

Lets split them into 3 groups:
8,2 = 10
7,2,1 = 10
6,4,1 = 11

There are a lot of ways of approaching this and it’s very interesting to see how a developer would do this.

3) Draw an image using GD primitives (squares, circles, lines). I promise you the developers will love you for this. Just let them go wild with their imaginations. They can draw a darts board, or a car or whatever. This will among other things showcase their inner “designer”. I’ve seen some clever developers draw some pretty complex stuff using simple algorithms and primitive figures.

4) Write unit tests for a few php classes/functions. This is a bit more boring but it will show you the experience the person had with Unit Testing and how his skill to identify bottlneck cases. The easiest version would be writing test cases for some array functions like usort(), array_reverse(), array_merge() etc.

If I think of any more fun and useful test tasks to solve, I’ll be adding them here. I’d love to hear your suggestions too =)

comments powered by Disqus