Interested in getting a job at Yahoo as PHP Developer, if so, Search This offers-up a selection of questions and answers that Yahoo have been known to throw-out when going to them for an interview. We are going to post the first three questions, but strongly suggest you visit the blog for a more detailed example of what to expect when knocking on Yahoo’s door:

  • Which of the following will NOT add john to the users array?

    1. $users[] = ‘john’;
      Successfully adds john to the array
    2. array_add($users,’john’);
      Fails stating Undefined Function array_add()
    3. array_push($users,‘john’);
      Successfully adds john to the array
    4. $users ||= ‘john’;
      Fails stating Syntax Error
  •  

  • What’s the difference between sort(), assort() and ksort?
    Under what circumstances would you use each of these?

    1. sort()
      Sorts an array in alphabetical order based on the value of each element. The index keys will also be renumbered 0 to length - 1. This is used primarily on arrays where the indexes / keys do not matter.
    2.  

    3. assort()
      The assort function does not exist, so I am going to assume it should have been typed asort().
    4.  

    5. asort()
      Like the sort() function, this sorts the array in alphabetical order based on the value of each element, however, unlike the sort() function, all indexes are maintained, thus it will not renumber them, but rather keep them. This is particularly useful with associate arrays.
    6.  

    7. ksort()
      Sorts an array in alphabetical order by index/key. This is typically used for associate arrays where you want the keys/indexes to be in alphabetical order.
    8.  

  • What would the following code print to the browser? Why?

     

    PHP:

    1. $num = 10;
    2. function multiply(){
    3.     $num = $num * 10;
    4. }
    5. multiply();
    6. echo $num; // prints 10 to the screen

    Since the function does not specify to use $num globally either by using global $num; or by $_GLOBALS['num'] instead of $num, the value remains 10.