php - 组合 2 个 For Each 循环 PHP
问题描述
我正在用 PHP 编写一个应用程序,它基本上会根据用户的输入生成动态页面。
我有变量的
$_POST['config'];
$_POST['configsize'];
通过 POST 数据以 CSV 格式提交。
我关心的是在表格中显示提交的数据。
<table class="table table-hover">
<tr class="text-capitalize">
<th>Unit Types</th>
<th>Unit Size</th>
<th>Get Price</th>
</tr>
'; // end content
// add <li>
$amenities1 = $_POST['config'];
$amenities2 = $_POST['configsize'];
$amenitisArr1 = explode(",", $amenities1);
$amenitisArr2 = explode(",", $amenities2);
// add values to html
foreach ($amenitisArr1 as $str1) {
$content_to_write .= '<tr><th>'.$str1.'</th>';
}
// add values to html
foreach ($amenitisArr2 as $str2) {
$content_to_write .= '<th>'.$str2.'</th>';
$content_to_write .= '<th>Book Now</th></tr>';
}
// continue in content
$content_to_write .= '</table>
我得到了输出,但是表格的对齐方式被折腾了!!
请帮助更正数据。
输出应该是这样的:
<table>
<tr>
<th>Unit Types</th>
<th>Units Size</th>
<th>Book Now</th>
</tr>
<tr> --- I want my For Each Loop to kick in here for as many times there is a CSV
<td>xxx</td>
<td>xxx</td>
<td>xxx</td>
</tr>
</table>
继续我的输出:
$amenities1 = $_POST['config'];
$amenities2 = $_POST['configsize'];
这是 CSV。这将从 $_POST['config'] 和 $_POST['configsize'] 发布
$amenities1 = 2BHK,3BHK
$amenities2 = 1092 Sq.ft,2098 Sq.ft
图 1 是电流输出。图 2 是预期的输出。
解决方案
您应该upload_tmp_dir
在您的php.ini
- 它不能在运行时设置,因为在您的脚本开始运行时,上传已经完成并且内容已经存储在临时文件中。
move_uploaded_file()
如果您需要动态创建此文件夹的名称 - 除了首先确保所需路径存在(例如,通过将第三个参数设置mkdir()
为 TRUE)时使用之外,您别无选择
推荐阅读
- uml - 复杂的 UML 用例图
- flutter - Flutter,如果出现内存泄漏怎么办?
- android - 使用 Unity 2021.1.18f1 构建时,Apk 构建具有双倍大小并且构建不可安装
- android - react-native-reanimated 不起作用
- web-scraping - scrapy 返回的多于所选元素
- algorithm - 具有高弹性的小消息(8位)纠错,最好的方法是什么?
- java - Log4j2 fatjar 以编程方式配置
- pyspark - ValueError 1:无法将列转换为布尔值:请使用 '&' 表示 'and'、'|' for 'or', '~' for 'not' 在构建 DataFrame 布尔表达式时
- sql - 有没有办法根据外部表自动刷新 Redshift Matearilized 视图?
- r - 在一个数据框中将日期转换为具有不同开始日期的天数