Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created August 19, 2014 08:05
Show Gist options
  • Save JacobHsu/20e68b99d98d13287310 to your computer and use it in GitHub Desktop.
Save JacobHsu/20e68b99d98d13287310 to your computer and use it in GitHub Desktop.
#PHP -associative array use the foreach loop.
<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.'=&gt'.$value."<br />";
}
?>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment