1. Create a file named: Functions1.php in your text editor. 2. Create a simple f
ID: 3550969 • Letter: 1
Question
1. Create a file named: Functions1.php in your text editor.
2. Create a simple function (no arguments) that displays your first and last name with a <br/><br/> tag, then call the function.
3. Create a function with one argument that displays "I live in --------", followed with a <br/><br/> tag, then call the function using your city as the argument.
4. Create a function with two arguments that displays a complex sentence similar to the end of video two, but you will then use two variables to show: 1) your favorite movie; 2) your favorite city; 3) your favorite car. You will obviously have to change your variable definitions after each run!
5. Code example: <?php function favorites($x, $y)
{echo "My favorite " . $x . " is " . $y . "!<br/><br/>";}
$fav = "pasta";
$type = "linguini";
favorites($fav,$type);
$fav = "book";
$type = "To Kill a Mockingbird";
favorites($fav,$type);
...
?>
John Smith
I live in Chula Vista!
My favorite movie is Chariots of Fire!
My favorite city is Paris!
My favorite car is Jaguar!
Explanation / Answer
<?php
function name(){
echo "John Smith<br>";
}
function place($city){
echo "I live in ", $city, "<br>";
}
function favorite($x,$y){
echo "My favorite ",$x," is ", $y,"<br>";
}
name();
place("New York");
$fav = "movie";
$ans = "Ironman";
favorite($fav,$ans);
$fav = "car";
$ans = "ferrari";
favorite($fav,$ans);
$fav = "city";
$ans = "New York";
favorite($fav,$ans);
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.