|
home—lects—exams—hws
breeze (snow day)
From PHP Visual Quickstart Guide by Larry Ullman
Originally based on notes by Jack Davis (jcdavis@radford.edu)
$soups = array('Monday'=> 'clam chowder', 'Tuesday' => 'vegetable', 'Wednesday' => 'chicken noodle'); |
print_r( range(5,10) ); print_r( range('a','z') ); print_r( range(0,100,3) ); // Indices [0,33]; last value is 99. |
foreach($array as $val) { statements… } |
foreach ($myArray as $key => $val) { statements… } |
It is also possible to use a regular
Note that for sparse arrays (i.e. skipped numeric indices),
a conventional
$data = array(17,18, 4=>21, 44 => 51, 52); /* array( 0 => 17 ,1 => 18 ,4 => 21 ,44 => 51 ,45 => 52 ) */ for ($i=0; $i < sizeof($data); ++i) { …$data[$i]… // $data[$i] ranges over: 17, 18, NULL, NULL, 21, NULL. } |
Array Sorting Function | ||
---|---|---|
Function | sorts by… | Maintains key-value associations? |
values | no | |
values (reverse) | no | |
values | yes | |
values (reverse) | yes | |
keys | yes | |
keys (reverse) | yes |
1
See Lisp's
home—lects—exams—hws
breeze (snow day)
©2011, Ian Barland, Radford University Last modified 2011.Dec.07 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |