Question: I need the codes to out print statement 1) //@TODO print Marvin the Martian as output, accessing his entry in the array. 2) * @TODO
I need the codes to out print statement
1) //@TODO print "Marvin the Martian" as output, accessing his entry in the array.
2) * @TODO create a foreach loop, similar to the one above, but that only prints the name * of the loony toon if the name begins with the letter, "M". */

* The following is an array in php. */ $loony Toons = array "Bugs Bunny", "Claude Cat", "Daffy Duck", "Elmer Fudd", "Marvin the Martian", "Merlin the Magic Mouse", "Michigan J. Frog", "Pepe Le Pew", "Porky Pig", "Road Runner", "Sylvester", "Tweety Bird", "Wile E. Coyote", "Yosemite Sam", "Tasmanian Devil" * * To access a variable stored in an array, I type the name of the variable, and then the index in the array. You can set your own indices, but if you do not, then PHP wall use the counting numbers, starting from zero. */ print ($loonyToons[0] . " "); //outputs the "first" element in the array... element zero. print (substr($loony Toons[1],0,2)); //outputs the first two letters of "Claude Cat". //print_r ($loony Toons); //the print_r will output the entire array. Uncomment this line, see what happens, th en comment it back, //@TODO print "Marvin the Martian" as output, accessing his entry in the array. // YOUR CODE HERE echo " "; //give some space * The "foreach" statement will loop over the entire contents of an array, exectuing code. * This is the same as saying, "for every x in loony Toons, print ...", but I say * it backwards, and use the word "as". foreach ($loonyToons as $x) { print($x . " is a Loony Toon. "); echo " "; 1/give some space /** * @TODO read about the function substr on the php documentation page (you get to find it this time). * Then, create a foreach loop, similar to the one above, but that only prints the name * of the loony toon if the name begins with the letter, "M". */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
