如何在php中用字符串连接Foreach循环 [英] How to concat foreach loop with string in php

查看:0
本文介绍了如何在php中用字符串连接Foreach循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中将Foreach循环与字符串连接在一起

$traning [] = '<tr>
    <td style="width:30%" id="trainingCode_' . $key + 1 . '">
    <select class="select2 form-control" data-live-search= "true" name="trainingCode[]">
        <option value="0">SELECT CODE</option>'.
        foreach ($code=0 as $row) {
            //
        }
    .'</select>
    </td>
   </tr>';

推荐答案

将代码拆分为每个人都能理解的部分:

$trContent = '<tr>
    <td style="width:30%" id="trainingCode_' . $key + 1 . '">
    <select class="select2 form-control" data-live-search= "true" name="trainingCode[]">
        <option value="0">SELECT CODE</option>';

// iterate over array and append to `$trContent`
foreach ($code as $row) {
    $trContent .= '<option></option>';
}

$trContent .= '</select>
    </td>
   </tr>';

$traning [] = $trContent;

这篇关于如何在php中用字符串连接Foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆