0

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?

7
  • 1
    Where's your second loop? Commented May 29, 2014 at 18:11
  • @Patrick Q - It's the exact same thing: foreach ($team as $row) Commented May 29, 2014 at 18:13
  • 1
    You could try reset($team). I honestly have no idea if this would work, but it might :) Commented May 29, 2014 at 18:13
  • 1
    I imagine it has something to do with the cursor type of your recordset. How do you create the $team variable? Commented May 29, 2014 at 18:15
  • 1
    Did you reset your $count variable? Commented May 29, 2014 at 18:15

1 Answer 1

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.