doutou3725 2014-01-17 05:56
浏览 19
已采纳

数组合和发布

This is a follow-up question to my previous post about array posting. I was advised to combine my arrays in order to dynamically generate table results for an email. So far, it looks like this:

$emp_names = is_array($_POST['emp_name']) ? $_POST['emp_name'] : array($_POST['emp_name']);
$emp_today_results = is_array($_POST['emp_today_result']) ? $_POST['emp_today_result'] : array($_POST['emp_today_result']);
$emp_today_goals = is_array($_POST['emp_today_goal']) ? $_POST['emp_today_goal'] : array($_POST['emp_today_goal']);
$emp_month_results = is_array($_POST['emp_month_result']) ? $_POST['emp_month_result'] : array($_POST['emp_month_result']);
$emp_month_goals = is_array($_POST['emp_month_goal']) ? $_POST['emp_month_goal'] : array($_POST['emp_month_goal']);
$emp_month_trends = is_array($_POST['emp_month_trend']) ? $_POST['emp_month_trend'] : array($_POST['emp_month_trend']);

$emp_results = array_combine($emp_names, $emp_today_results, $emp_today_goals, $emp_month_results, $emp_month_goals, $emp_month_trends);

That collects and combines all the arrays. Then, I don't now how to use them. This doesn't work (I assume because there is no "as" in the brackets. Any idea how to make it work?

foreach ($emp_results) {
        $htmlBody .= "

        <tr>
        <td>{$emp_name}</td>
        <td>{$emp_today_result}</td>
        <td>{$emp_today_goal}</td>
        <td>{$emp_month_result}</td>
        <td>{$emp_month_goal}</td>
        <td>{$emp_month_trend}</td>
        </tr>";

        }
  • 写回答

2条回答 默认 最新

  • dsf5989 2014-01-17 06:09
    关注
    $values = explode('|', 'emp_name|emp_today_result|emp_today_goal|emp_month_result|emp_month_goal|emp_month_trend');
    foreach ($values as $value) {
        $$value = (array)$_POST[$value];
    }
    for ($i = 0; $i < count($emp_name); $i++) {
        $emp_results = array();
        foreach ($values as $value) {
            $emp_results[] = ${$value}[$i];
        }
        $htmlBody .= '<tr><td>' . implode('</td><td>', $emp_results) . '</td></tr>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致