function
Posted: Mon Dec 12, 2011 1:20 pm
I have created a function that accepts two arguments a first and a last name. the function returns the initials in a single string. I need to call the above function 5 times, passing in 5 different names and print the value returned each time. I can't figure out how to loop the function 5 times so the user can enter a different name each time and it print out each of the five names' initials. here's what i have so far.
index.php
functions.php
index.php
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Functions!</title>
</head>
<body>
<p>Please enter your first and last name so I can
give you your initials.</p>
<form action="functions.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" /></p>
<input type="submit" name="submit" value="Get My Initials" />
</form>
</body>
</html>Code: Select all
<?php
function first_and_last($first_name, $last_name ) {
return $first_name[0] . '. ' . $last_name[0] . '.';
}
echo first_and_last($_POST['first_name'], $_POST['last_name']);
?>