Multiple return statements in a function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I tend to put my return value in a variable and at the end of the
function I have 1 return statement.
I have seen others doing returns in the middle of the function.

Example how I do it:
function check($a) {
  $return='';
  if ( is_array( $a ) ) {
    $return='Array';
  } else {
    $return='Not Array';
  }
  return $return;
}

Example of the other method:
function check($a) {

  if ( is_array( $a ) ) {
    return ('Array');
  } else {
    return ('Not Array');
  }
}

What is your take? And is there any benefit to either method?


-- 
Peter van der Does

GPG key: E77E8E98
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderdoes@xxxxxxxxx

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux