foreach with PHP for two strings

Asked

Viewed 56 times

0

Colleagues.

I have the following result from the bank:

Questions: 1,2,3 Answers: A,B,C

I would like it to be as follows:

1 - A; 2 - B; 3 - C;

I tried to use two foreach, but he’s repeating:

1 - A; 1 - B; 2 - A; 2 - B;

I did it that way:

$explodeR = explode(",",$jmTurmas->Respostas;
$explodeQ = explode(",",$jmTurmas->Questoes);

       foreach($explodeQ as $exQ){
                foreach($explodeR as $exR){
                  echo $exQ. " - ".$exR."<br>"; 
                }
            } 

1 answer

1


So it must be:

$explodeR = explode(",",$jmTurmas->Respostas;
$explodeQ = explode(",",$jmTurmas->Questoes);

foreach($explodeQ as $exQkey => $exQ)
{
    echo $exQ. " - ".$explodeR[$exQkey]."<br>"; 
} 
  • Thanks lvcs. It worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.