See my comments in the code. You didn't make the $i
iterator a valid PHP variable, so FYI: All PHP variables must be prefixed with a $
.
<?php
// You declare your functions typically in the global scope, not
// within a for or any other loop.
// NOTE: $name is a required function parameter in this function.
function places($name, $location="Minneapolis", $lodging="Mom's house") {
return "$name enjoys going to $location and staying at $lodging while on vacation.";
}
// Note, I've got $people setup to have arrays that can be passed
// containing a "name, city, hotel" syntax. This is equivalent to
// $people[loop index][0] ~ $people[loop index][name]
// $people[loop index][1] ~ $people[loop index][city]
// $people[loop index][2] ~ $people[loop index][hotel]
$people = array(
array("James", "Brooklyn", "Granada Inn"),
array("Betsy", "Memphis", "Tennessee Hotel"),
array("Andrew", "San Francisco", "101 Hotel"),
array("Marvin", "San Diego", "Oceanview Beach Resort"),
array("Sara", "Orlando", "Disney World"),
array("Alicia", "Hilton Head", "Vincent Inn")
);
// Cache the count of the $names array members
$c_people = count($people);
// Loop and echo.
for ($i = 0; $i < $c_people; $i++) {
echo places($people[$i][0], $people[$i][1], $people[$i][2]) . "
";
}
?>
http://codepad.org/QHh83cKz
OUTPUTS
James enjoys going to Brooklyn and staying at Granada Inn while on vacation.
Betsy enjoys going to Memphis and staying at Tennessee Hotel while on vacation.
Andrew enjoys going to San Francisco and staying at 101 Hotel while on vacation.
Marvin enjoys going to San Diego and staying at Oceanview Beach Resort while on vacation.
Sara enjoys going to Orlando and staying at Disney World while on vacation.
Alicia enjoys going to Hilton Head and staying at Vincent Inn while on vacation.