Title: how to index arrays and show all the elements and values of array
Description: how to index arrays and show all the elements and values of array Snippets
Tags: how, to, index, arrays, and, show, all, the, elements, and, values, of, array
Info: This Post Has Been Viewed 1640 Times SinceSun Feb 24, 2008 12:07 pm Author hostman With 0 Replies #5798

how to index arrays and show all the elements and values of array

indexing arrays with string



so far i've only seen arrays indexed by itergers, but it is also permissbible to use strings. sometimes there are called assocaited arrays, or hashes. they are helpful in situations where you are colectin differen type so information into one array. you could build inot your code a system where element zeor is a name, element one is a location, and element two is an occupation

here is an example:

<?php
// fill in some information
$userinfo["Name"] = "John Doe";
$userinfo["Location"] = "San Francisco";
$userinfo["Occupation"] = "Programmer";

foreach($userinfo as $key=>$value) {
print("$key is $value.<br>");
}
?>


the above will output:
Name is John Doe
Location is San Francisco
Occupation Programmer
Comments (0)
View Top Comments
Share
| More