Jump to content

return?


ohdang888

Recommended Posts

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

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.