---------------------------------------------------
| Date: 2003-03-16 14:19:13 |
| Filename: ass_array.php |
| Author: detour@metalshell.com |
| |
| http://www.metalshell.com/ |
---------------------------------------------------
"white", "up" => "down", "left" => "right", "night" => "day");
/** Displaying the Values **/
echo('Display values individually
');
echo($ass_array["black"] . ', ' . $ass_array["up"] . '
');
echo('Display all values.
');
foreach($ass_array as $key => $value)
echo($key . ' = ' . $value . '
');
/* You can also sort the array by either the key or value.
*
* asort() - sort in ascending order
* arsort() = sort in descending order
* ksort() = sort by the key in ascending order
*
*/
asort($ass_array);
// You can also cycle through the array by using a pointer
// Use reset() to set the pointer at the beginning of the array
reset($ass_array);
$num = count($ass_array);
echo('Display all values using a pointer. Note they are sorted now.
');
for($x = 0; $x < $num; $x++) {
echo(key($ass_array) . ' = ' . current($ass_array) . '
');
// Increment the pointer
next($ass_array);
}
?>