Archive for March 6th, 2009

I bet you didn’t know, that switch can be used to answer the question: “Which of the N following statements is true?” Continue reading ‘Trick with php switch()’ »

As you know, PHP can return only one value from the function. However, there is a simple workaround – we return an indexed array from function and immediately split it into variables using list():

  1.  
  2. function ret()
  3. {
  4. //something useful here
  5. return array($varA, $varB);
  6. }
  7. list($a, $b) = ret();//we’ll have $varA in $a and $varB in $b after this
  8.