Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组合并和过帐_Php_Arrays - Fatal编程技术网

Php 数组合并和过帐

Php 数组合并和过帐,php,arrays,Php,Arrays,这是我上一篇关于数组发布的文章的后续问题。我被建议合并我的数组,以便为电子邮件动态生成表结果。到目前为止,看起来是这样的: $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($

这是我上一篇关于数组发布的文章的后续问题。我被建议合并我的数组,以便为电子邮件动态生成表结果。到目前为止,看起来是这样的:

$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);
它收集并合并所有阵列。然后,我现在不知道如何使用它们。这是行不通的(我想是因为括号里没有“as”。你知道怎么做吗

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>";

        }
foreach($emp\u结果){
$htmlBody.=”
{$emp_name}
{$emp_今日结果}
{$emp_今日目标}
{$emp_month_result}
{$emp_month_goal}
{$emp\u month\u trend}
";
}

这样做..这里不需要
数组\u组合

$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']);

for($i=0;$i<count($emp_names);$i++)
{
$htmlBody .= "

        <tr>
        <td>$emp_name[$i]</td>
        <td>$emp_today_result[$i]</td>
        <td>$emp_today_goal[$i]</td>
        <td>$emp_month_result[$i]</td>
        <td>$emp_month_goal[$i]</td>
        <td>$emp_month_trend[$i]</td>
        </tr>";
}
echo $htmlBody;
$emp_name=is_数组($_POST['emp_name'])?$_POST['emp_name']:数组($_POST['emp_name']);
$emp_today_result=is_数组($_POST['emp_today_result'])?$_POST['emp_today_result']:数组($_POST['emp_today_result']);
$emp_today_goals=是数组($_POST['emp_today_goal'])?$_POST['emp_today_goal']:数组($_POST['emp_today_goal']);
$emp_month_results=is_数组($_POST['emp_month_result'])?$_POST['emp_month_result']:数组($_POST['emp_month_result']);
$emp_month_goals=is_数组($_POST['emp_month_goals'])?$_POST['emp_month_goals']:数组($_POST['emp_month_goals']);
$emp_month_trends=is_数组($_POST['emp_month_trends'])?$_POST['emp_month_trends']:数组($_POST['emp_month_trends']);
对于($i=0;$i
$values=explode(“|”),“emp_name | emp_today|u result | emp_today|u goal | emp_month|u goal | emp_month|u trend”);
foreach($value作为$value){
$$value=(数组)$\u POST[$value];
}
对于($i=0;$i
array\u combine
只接受两个参数。哦,我明白了。关于如何返回属于$emp\u name的每个值,有什么建议吗?提示:您可以这样缩短行:
$emp\u xxx=(array)$\u POST['emp\u xxx']
-它强制一个没有数组的数组。谢谢,Yashua。这很有帮助。我试过了,但仍然不起作用。PHPMailer正在通过电子邮件发送$htmlBody,但字段仍然是空的。你能
变量转储($htmlBody)吗
并让我知道输出结果?好吧,这封电子邮件中有很多内容。这是一封html电子邮件,由另一个文件上发布的值生成。var_dump给了我字符串(16317)”(此处为我的html电子邮件)”,所有值仍然缺失。嗨,Shankar。我做了一些工作,但现在这些值以数组[0]的形式返回例如,你知道为什么吗?每行在方括号中都有一个新的数字。数组[0]然后是新行数组[1]…等等。您的答案至少返回了值,但所有值都返回到一行中。仍然没有任何结果。这些值实际上显示在一行中,并且值交替出现。我得到的是Mike John 1 4 2 5 3 6,而不是Mike 1 2 3 3 3 3 3 3 3 3 3 3,而不是第一行中的Mike 1 2 3 3和第二行中的John 4 5 6。
$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>';
}