How to concat foreach loop with string in php(如何在php中用字符串连接Foreach循环)
本文介绍了如何在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循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:如何在php中用字符串连接Foreach循环
基础教程推荐
猜你喜欢
- Laravel Dusk:FacebookWebDriverExceptionUnknownErrorException:未知错误:NET::ERR_CONNECTION_REJECTED 2022-01-01
- 为 iPhone APNS 使用 PHP 时出错 2022-01-01
- 使用 jQuery Ajax 删除 mySQL 表行 2021-01-01
- PHP中如何获取当前用户的请求参数? 2023-09-25
- PHP - 从时差中排除所有非营业时间/天 2022-01-01
- File_get_contents 不起作用? 2021-01-01
- 使用 php 7 运行 composer,但为 php 5 安装包 2022-01-01
- 在 Magento 中设置全局变量,GUI 方式? 2021-01-01
- 雄辩的 laravel WhereIn All 2021-01-01
- PHP 5 反射 API 性能 2021-01-01
