Created
August 19, 2014 08:05
-
-
Save JacobHsu/20e68b99d98d13287310 to your computer and use it in GitHub Desktop.
#PHP -associative array use the foreach loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>I am the King of Arrays!</title> | |
</head> | |
<body> | |
<p> | |
<?php | |
// On the line below, create your own associative array: | |
$myArray = array('one'=>'Jacob','two'=>2,'three'=>'King'); | |
// On the line below, output one of the values to the page: | |
echo $myArray['one']."<br /><br />"; | |
// On the line below, loop through the array and output | |
// *all* of the values to the page: | |
foreach ($myArray as $key => $value){ | |
echo $key.'=>'.$value."<br />"; | |
} | |
?> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment