Skip to content

Instantly share code, notes, and snippets.

@BLamy
Created August 29, 2016 14:04
Show Gist options
  • Save BLamy/f379366fefa5e4bf5aed467b5212be7d to your computer and use it in GitHub Desktop.
Save BLamy/f379366fefa5e4bf5aed467b5212be7d to your computer and use it in GitHub Desktop.
<?php
echo "<h1> #1 - Standard indexed Array</h1>";
$array1 = array(55, 66, 77, 88);
$array1[] = 99;
$array1[0] = 11;
for ($i = 0; $i < count($array1); $i++) {
echo $array1[$i]."<br />";
}
echo "<h1> #2 - Associative array value</h1>";
$array2 = array(
"RIT" => "http://www.rit.edu",
"Google" => "http://google.com",
);
$array2['CNN'] = "http://www.cnn.com";
foreach($array2 as $v) {
echo "$v <br/>";
}
echo "<h1> #3 - Associative array value and key</h1>";
foreach($array2 as $k=>$v) {
echo "$k = $v <br/>";
}
echo "<h1> #4 - Associative array build some links</h1>";
foreach($array2 as $k=>$v) {
echo "<a href='$v'>$k</a><br/>";
}
echo "<h1> #5 - Nested Associative array - one at a time</h1>";
$array3 = array(
'colors' => array("red", "green", "blue"),
'shapes' => array('circle', 'square', 'triangle', 'rectangle')
);
foreach($array3['colors'] as $v) {
echo "$v</br>";
}
foreach($array3['shapes'] as $v) {
echo "$v</br>";
}
echo "<h1> #1 - Standard indexed Array</h1>";
foreach($array3 as $v => $items) {
echo "<h2>$k</h2>";
foreach ($items as $oneItem) {
echo "$oneItem<br />";
}
echo "<hr />";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment