Jump to content

function() return


robert_gsfame
 Share

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
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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.