I have an associative array, $teams_name_points
. The length of the array is unknown.
How do I access the first and forth value without knowing the key of this array in the easiest way?
The array is filled like this:
$name1 = "some_name1";
$name2 = "some_name2";
$teams_name_points[$name1] = 1;
$teams_name_points[$name2] = 2;
etc.
I want to do something like I do with an indexed array:
for($x=0; $x<count($teams_name_points); $x++){
echo $teams_name_points[$x];
}
How do I do this?
foreach($teams_name_points as $team_name => $points) {
It would also seem you have access to the key information so if you want the points for a certain team, you would just look it up using the appropriate index.