user2509541
user2509541

Reputation: 268

PHP Loop through an array second time (foreach)

I have a foreach to loop through the data provided by a PDO SQL query:

foreach ($team as $row){
    $count++;
    $teamNumber = 'team'.$count;
    if ($currentScores[0]['team'.$count] == ""){
        $red = "red";
    }
    echo "<strong><font color='".$red."'>".$row['name']."</font></strong>";
    echo $currentScores[0]['team'.$count];
    if ($count < 2) 
        echo " vs ";
}

Now, I want to loop again through the $team array but it just returns the last value of the array during the second loop.

I tried the same thing:

foreach ($team as $row) {
.....
.......
}

How could I run again through the array?

Upvotes: 0

Views: 882

Answers (1)

Bill
Bill

Reputation: 11

Simple enough, just do a foreach loop on $row as you have previously.

foreach($array as $key => $val) {
    foreach($val as $a => $b) {
        echo $b;
    }
}

Upvotes: 1

Related Questions