Re: Multiple return statements in a function.

From: Date: Thu, 23 Apr 2009 12:25:44 +0000
Subject: Re: Multiple return statements in a function.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-291856@lists.php.net to get a copy of this message
Peter van der Does wrote: > 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? It's only about style and coding logic. In essence, all the return does is pop the previous IP off the stack and adjust the stack pointer. It doesn't matter where you do that. /Per -- Per Jessen, Zürich (16.2°C)

« previous php.general (#291856) next »