Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a file named: Functions3.php in your text editor. 2. Create a variable

ID: 3550971 • Letter: 1

Question

1.    Create a file named: Functions3.php in your text editor.

2.    Create a variable ($world) equal to the city you live in (global scope); then create a simple function (no arguments) called 'where' that, if set, displays "My living space is " . $world . ".<br/><br/>"; Then reset your variable to your street name (local scope) before closing the function. Do not call the function yet!

3.    Now display your variable after "Where do I live?"  Then call your function and again display the previous question and your variable. If you studied the example in video 5, this should be fairly simple!

4.    Create a function that passes three arguments ($name, $loc, $rest) with default values that returns a sentence stating that a person ($name) likes to vacation in a place ($loc) and stay at a hotel ($rest).  Then call the function six times using a different person, place, lodging in each call.  Finally, display the default values of the function.  Pay close attention to video six and what it has to say about displaying a returned value!

5.    Here is a sample of what your output should look like.

Where do I live? Chula Vista

My living space is Chula Vista.

Where do I live? Main Street

===============

Allison enjoys going to Las Vegas and staying at Circus, Circus while on vacation.

Barry enjoys going to Zion National Park and staying at Zion Lodge while on vacation.

Cathy enjoys going to New York City and staying at the Waldorf-Astoria while on vacation.

Henry enjoys going to Paris and staying at Hotel Gare De Lyon while on vacation.

Ivana enjoys going to Sydney and staying at Carlton Crest Hotel while on vacation.

Jake enjoys going to Syros, Greece and staying at Hotel Benois while on vacation.

Default Values - Echo to screen:

John Doe enjoys going to Hawaii and staying at Kilauea while on vacation.


Explanation / Answer

<?

$world = "Paris";


function where(){

if($world){

echo "My living space is ",$world,"<br>";

$world="Main Street";

}

}


echo "Where do I live?", $world,"<br>";

where();

echo "Where do I live?", $world,"<br>";


function holiday($name="John Doe",$loc="Hawaii",$stay="Kilauea"){

echo $name, " enjoys going to ",$loc, " and staying at ",$stay, " while on a vacation.<br>";

}


holiday("Allison","Las Vegas","Circus,Circus");


holiday("Barry","Zion National Park","Zion Lodge");


holiday("Cathy","New York City","Waldorf-Astoria");


holiday("Henry","Paris","Hotel Gare De Lyon");


holiday("Ivana","Sydney","Carlton Crest Hotel");


holiday("Jake","Syros, Greece","Hotel Benois");


holiday();