How to ace a PHP job test in South Africa

Initial Preparation

First of all do a project in PHP that utilises the database. I am talking about pure PHP and not a framework. Remember to turn make sure you set the following configuration settings.

display_errors = 1;

You can always view the php documentation which is always of great help.

 Get ready for some specialised questions

The off-the-wall questions

  • What do you think of garden gnomes? Your answer should include some form of analysis and deduction.
  • Why are man-hole covers a circle? The answer is because it is not possible for the cover to fall into the hole that way.

PHP Specific Questions

Increment and Decrement Operators

Example Name Effect
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
–$a Pre-decrement Decrements $a by one, then returns $a.
$a– Post-decrement Returns $a, then decrements $a by one.

Question 1: ++$a * $a++ + $a = ? (Where $a = 5)

Answer 1: 6 * 5 + 5 = 35

Bitwise Operators

Example Name Result
$a & $b And Bits that are set in both $a and $b are set.
$a | $b Or (inclusive or) Bits that are set in either $a or $b are set.
$a ^ $b Xor (exclusive or) Bits that are set in $a or $b but not both are set.
~ $a Not Bits that are set in $a are not set, and vice versa.
$a << $b Shift left Shift the bits of $a $b steps to the left (each step means “multiply by two”)
$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means “divide by two”)

Question 2: echo 5 & 7;

Answer 2:

5 = 0101
7 = 0111

Now AND the bits

Answer = 0101 (5)

Question 3: echo 12 ^ 9;

Answer 3:

12 = 1100
9  = 1001
Now XOR the bits
Answer = 0101 (5)

Question 4:$x = 5; echo $x >> 2;
Answer 4:

5 = 0101
Shift bits 2 steps to the right

Answer = 0001 (1)

Learn some functions of the PHP library

array_shift  – Shifts an element off the beginning of an array

array_combine – Creates an associative array by using 1 for keys and 1 for values

final keyword – Prevents overriding and extension of the class

interfaces – Interfaces specify which methods a class must implement, but does not specify the code for the methods.

suppression of errors

Learn some permutations, combinations and factorial

I’m not good at these and if anyone has a tutorial or content to add please free to comment.

Here are some resources that may help, if you find out how to do these please comment below.

Circular Permutations

Example Permutation and Combination Question

Maths is Fun

If ABCDEFGH are sitting at a table, where the configuration of the seats is 1 at each head of the table, and 3 on either side. If A can’t sit next to B and F can’t sit G, how many different configurations are there?

How many different numberplates can be made, if the numberplate must contain only digits and no signle digit can be repeated if there are 5 spaces for digits on the numberplate?

Please leave comments if you have anything else to add.

PHP job test