My array looks like this:
Array ( [Bob] => Red [Joe] => Blue )
But it could be any number of people, like this:
Array ( [Bob] => Red [Joe] => Blue [Sam] => Orange [Carla] => Yellow)
Basically I want PHP to take this array and echo it so that it comes out looking like:
Bob - Red
Joe - Blue
Sam - Orange
Carla - Yellow
I know I need to loop through the array, this is what I tried:
for ($row = 0; $row < count($array); $row++) {
echo $array[0] . " - " . $array[1];
}
I get the following error: Undefined offset: 0, Undefined offset: 1
I realize that this doesn't work because I'm trying to use index's when the values of the array are strings. Is there any way I can use positional index's like this with a multidimensional array that only contains strings?
Thanks