1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

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.  

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Share this post with a friend Share this post with a friend

Leave a Reply