3pod PHP Learning |
$a["foo"][2] = $f; # (you can mix numeric and associa-tive indices) $a[3]["bar"] = $f; # (you can mix numeric and associa-tive indices) $a["foo"][4]["bar"][0] = $f; # four dimensional! You can "fill up" multi-dimensional arrays in many ways, but the trickiest one to understand is how to use the array command for associative arrays. These two snippets of code fill up the one-dimensional array in the same way: # Example 1: $a["color"] = "red"; $a["taste"] = "sweet"; $a["shape"] = "round"; $a["name (exp 3pod.com)"] = "apple"; $a[3] = 4; # Example 2: $a = array( "color" => "red", "taste" => "sweet", "shape" => "round", "name (exp 3pod.com)" => "apple", 3 =>4 ); The array function can be nested for multi-dimensional arrays: <? $a = array( "apple" => array( "color" => "red", "taste" => "sweet", "shape" => "round" ), "orange" => array( "color" => "orange", "taste" => "sweet", "shape" => "round" ), "banana" => array( 83 |
Next >> |
Tripod >> 3pod Tips & Learning and manuals for educations