robert_gsfame Posted April 3, 2011 Share Posted April 3, 2011 let say i have a function function checkme($x) { if(strlen($x)>10) { return $x; } else { return false; } } $variable=checkme("5"); so two questions i wish to ask... 1. If i wish to get the empty string for the $variable, then is it correct to have return false there? 2. If it is true that return shall not be used twice in a function as it will somehow reduce bytes space or something like that?? thx in advance Link to comment https://forums.phpfreaks.com/topic/232548-function-return/ Share on other sites More sharing options...
rpmorrow Posted April 3, 2011 Share Posted April 3, 2011 1. Yes, FALSE is fine, or you could have NULL or... return ""; They are equivalent, but are NOT identical. (See if ===) 2. you can have return multiple times in a function because only one of them can ever call at once. As soon as whatever conditions you set executes the first "return" then the function is finished and any others are irrelevant at that time. Link to comment https://forums.phpfreaks.com/topic/232548-function-return/#findComment-1196158 Share on other sites More sharing options...
JasonLewis Posted April 3, 2011 Share Posted April 3, 2011 I've never heard of your #2 statement, although it could be true. Who knows. I'd doubt it. I sometimes do my returns like this too: if(strlen($x) > 10){ return $x; } return false; Just a personal thing. Link to comment https://forums.phpfreaks.com/topic/232548-function-return/#findComment-1196159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.