Array
(
[0] => 42
[Apples] => 21
[1] => Foo
[FavNumber] => Half of 84
)
42
21
Foo
Half of 84
INDEX: 0 -- VALUE: 42
INDEX: Apples -- VALUE: 21
BINGO!!!!
INDEX: 1 -- VALUE: Foo
INDEX: FavNumber -- VALUE: Half of 84
END OF OUTPUT
Source Code of arrays.php
<?php
$myArray = array();
$myArray[0]=42;
$myArray['Apples']=21;
$myArray[1]="Foo";
$myArray['FavNumber']="Half of 84";
echo "<pre>";
print_r($myArray);
//SUPER COOL FEATURE? 'FOREACH' Loops
//This iterates through each item in the array
foreach($myArray as $value) {
echo $value."\n";
}
//This iterates through each item in the array
// AND let's us see the index's value as well
foreach($myArray as $idx=>$value) {
echo "INDEX: ".$idx. " -- VALUE: ".$value."\n";
if ($idx === "Apples") {
echo "BINGO!!!!\n";
}
}
echo "</pre>";
?>
<?php //WILL DISPLAY CODE OF THIS FILE ON THE WEBPAGE//
######################################################################
echo "<br/><br/><hr><hr>";
echo "<h2 style='text-align:center'>END OF OUTPUT</h2>\n";
echo "<hr><hr>";
echo "<h2><br>Source Code of ".basename((string)__FILE__) . "</h2><hr>";
show_source(__FILE__);
#######################################################################
?>