- Forums
- Snippets
- How To Index Arrays And Show All The Elements And Values Of Array
This Page Contains information about How To Index Arrays And Show All The Elements And Values Of Array By wallpaperama in category Snippets with 0 Replies. [1380], Last Updated: Sat May 18, 2024
wallpaperama
Sun Feb 24, 2008
0 Comments
2663 Visits
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