C
C
Cheizer2018-02-18 15:46:15
PHP
Cheizer, 2018-02-18 15:46:15

How to do php array insertion in html?

Can't change email send code in php. Previously, there were only POST variable fields, there were no problems, it was just sent

if (isset($_POST["color"])) {
$color = $_POST["color"];  
}
if($color!='nope'){
    $color_htm='<tr>Цвет: <td>'.$color.'</td></tr> ';
}
$messageBody ='
<td> '.$color_htm.'</td>
';

Well, then sending, everything is ok.
BUT now there is an array in the POST parameter, and I can't print it in any way in this construction.
Well, it doesn’t want to work like that, the syntax error is constant. :( How is it done guys??
$messageBody ='
<table>
<tr><td> '.$color_htm.'</td></tr>
<tr><td>'.foreach ($useroption as $value) {echo $value;}.'
</table>';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-18
@Cheizer

Good afternoon.
There is such a construct as foreach() ;
Here, with its help, iterate over the array.
Something like this:

foreach($array as $key => $value){
    echo $value;
}

ps If you want to substitute the result of the loop into a variable, then first get the result of the work, and then substitute it into the variable.
Approximately like this:
$result = '';
foreach ($useroption as $value)
{
     $result .= $value;
}
$messageBody ='
<table>
<tr><td> '.$color_htm.'</td></tr>
<tr><td>'.$result.'</td></tr>
</table>';

Or, if you need to substitute several rows into the table, you can do this:
foreach ($useroption as $value)
{
     $result .= '<tr><td>'.$value.'</td></tr>';
}
$messageBody ='
<table>
<tr><td> '.$color_htm.'</td></tr>
'.$result.'
</table>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question