Litebreeze Php Developer Online Interview Question


Today I would like to share interview question for PHP Developer. Litebreeze (Kochi) conduct online test for PHP developer. The online test aims at testing the quality of your code. You will develop one function. Their focus is on the neatness of the solution; logic used, code efficiency and formatting. Minimize the number of lines; you don't have to declare variable, add comments or write any HTML (except maybe a pre tag to format array output).

There will be only one question and the time limit will be 45 Minutes. If you complete earlier we recommend that you take some extra time to perfect the code, such as formatting and minimizing the number of lines of code used.

The functions you develop should display the exact return values given in the test instructions.

Question is like this, you need to write a function that will fetch 5 random number (between 0 & 9) and create a associate array such that key will the the random value that generated and value as 2 * preciding key (for 1st key value will be 2 * key of last key). For example array([1]=>6, [5]=>2, [4]=>10, [9]=>8, [3]=>18).

Then you need to print the array using print_r, later sort array in ascending order and then print again.

Your answer will be some what like this,

<?php
function ary(){
$a1=rand(0,9);$a2=rand(0,9);$a3=rand(0,9);$a4=rand(0,9);$a5=rand(0,9);
return(array($a1=>$a5*2,$a2=>$a1*2,$a3=>$a2*2,$a4=>$a3*2,$a5=>$a4*2));
}
print_r($a=ary());
asort($a);
print_r($a)
?>

This answer may or mayn't be correct. Please share your answer.

.