ohdang888 Posted May 27, 2008 Share Posted May 27, 2008 what does "return $var" do at the end of the function? thanks! Link to comment https://forums.phpfreaks.com/topic/107530-return/ Share on other sites More sharing options...
BlueSkyIS Posted May 27, 2008 Share Posted May 27, 2008 returns $var to the calling variable: function not_much() { $var = 10; return $var; } echo not_much(); output: 10 Link to comment https://forums.phpfreaks.com/topic/107530-return/#findComment-551200 Share on other sites More sharing options...
ohdang888 Posted May 27, 2008 Author Share Posted May 27, 2008 i'm sorry, but still don't understand that at all... whats the point of using it? Link to comment https://forums.phpfreaks.com/topic/107530-return/#findComment-551203 Share on other sites More sharing options...
BlueSkyIS Posted May 27, 2008 Share Posted May 27, 2008 you can send information into a function to have the function to something. the normal way of getting information back out is to return it to the call. here is a less silly example: function validEmail($eaddr) { if (!ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $eaddr)) { return false; } return true; } $some_email = "aserasetrw4tq34tq34q35hbdfvf"; if (validEmail($some_email)) { echo "$some_email is valid"; } else { echo "$some_email is NOT valid"; } or here is a function that takes several parameters and returns an HTML <SELECT> : function formSelect($var_name, $selected, $options, $empty = "", $jscript="", $style="") { // Create and return an HTML <SELECT> if ($jscript > "") { $jscript = " $jscript "; } if ($style > "") { $style = " style='$style'"; } $select = "<SELECT NAME='$var_name'$jscript$style>\n"; if ($empty > "") { $select .= "<OPTION VALUE=''>$empty</OPTION>\n"; } foreach($options AS $value=>$option) { $select .= "<OPTION VALUE='$value'"; if ($value == $selected) { $select .= " SELECTED"; } $select .= ">$option</OPTION>\n"; } $select .= "</SELECT>\n"; return $select; } Link to comment https://forums.phpfreaks.com/topic/107530-return/#findComment-551210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.