Include the result of a Foreach loop in a variable in PHP ? ( for the function mail() )

email, foreach, include, php, variables

Solution

$msg = '<html><head><title>Commande de photos</title></head><body><p>Voici la liste des photos demand&eacute;es :</p><ul>';
foreach($tab as $val){
     $msg .= '<li>' . $val . '</li>';
}
$msg .= '</ul>';
mail($destinataire,$sujet,$msg,$headers);

The trick here is the .= concatenation operator. For example:

$x = 'abc';
echo $x; // echoes 'abc'
$x .= 'def';
echo $x; // echoes 'abcdef'

Problem

I'm French so I might not speak English very well. I'm trying to "put" the result of a foreach loop in a variable like this: ``` $msg = '<html><head> <title>Commande de photos</title> </head><body> <p>Voici la liste des photos demand&eacute;es :<br /> <ul> HERE I WANT TO "PUT" THE RESULT OF THE FOREACH LOOP</ul>'; ``` Here is my foreach loop: ``` foreach($tab as $val){ echo('<li>'.$val.'</li>'); } ``` Then the `$msg` enter in the composition of the function `mail()` like this: ``` mail($destinataire,$sujet,$msg,$headers); ``` So how can I do this to include the result of foreach in a message because I have already a bug?

Original source