Jump to content

function() return


robert_gsfame

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.