Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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
如果foreach循环中的值不匹配+;php_Php_Html_Php 7_Php 5.6 - Fatal编程技术网

如果foreach循环中的值不匹配+;php

如果foreach循环中的值不匹配+;php,php,html,php-7,php-5.6,Php,Html,Php 7,Php 5.6,我必须按照th值匹配显示td值。下表中的th有月份日期。在$monthdays中,我得到了月份天数计数,在$listmonthdisplay中,我得到了月份的所有日期。 在$employeeDetail数组中,我得到了月份日期。在表中,我正在为每个人显示Attendance\u date做准备,如果Attendance\u date等于$listmonthdisplay,但当$employeeDetail数组中缺少任何日期时,则循环失败或不继续。这里如何正确映射tb值 $monthdays=28

我必须按照th值匹配显示td值。下表中的th有月份日期。在
$monthdays
中,我得到了月份天数计数,在
$listmonthdisplay中,我得到了月份的所有日期。
$employeeDetail
数组中,我得到了月份日期。在表中,我正在为每个人显示Attendance\u date做准备,如果Attendance\u date等于
$listmonthdisplay
,但当
$employeeDetail
数组中缺少任何日期时,则循环失败或不继续。这里如何正确映射tb值

$monthdays=28;
$listmonthdisplay=[
  "0"=>"01-02-2019",
  "1"=>"02-02-2019",
  "2"=>"03-02-2019",
  "3"=>"04-02-2019",
  "4"=>"05-02-2019", ............"28"=>"05-02-2019"
]

$employeeDetail=[
     "0"=>["attendence_date"=>"01-02-2019"],
     "1"=>["attendence_date"=>"02-02-2019"],
     "2"=>["attendence_date"=>"05-02-2019"],
     "3"=>["attendence_date"=>"08-02-2019"],
     "5"=>["attendence_date"=>"09-02-2019"]
  ]   
 <table>
  <tr>
    <?php for($i=0;$i<$monthdays;$i++){ ?>
    <th><?php echo $listmonthdisplay[$i]?></th>
    <?php }?>
 </tr>
<tr>
  <?php for($i=0;$i<$monthdays;$i++){ ?>
  <td>
 <?php
   if((isset($employeeDetail[$i]) && $listmonthdisplay[$i]==$employeeDetail[$i]['attendence_date']){
     echo $employeeDetail[$i]['attendence_date'];
   }?>
 </td>
  <?php }?>
 </tr>

 </table>


Current output:

 <table>
  <tr>
    <th>01-02-2019</th>
    <th>02-02-2019</th>
    <th>03-02-2019</th>
    <th>04-02-2019</th>
    <th>05-02-2019</th>
    <th>06-02-2019</th>
    <th>07-02-2019</th>
    <th>08-02-2019</th>
    <th>09-02-2019</th>........<th>28-02-2019</th>
 </tr>
<tr>
    <td>01-02-2019</td>
    <td>02-02-2019</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>.......<td></td>
 </tr>

 </table>


Expected output:

 <table>
  <tr>
    <th>01-02-2019</th>
    <th>02-02-2019</th>
    <th>03-02-2019</th>
    <th>04-02-2019</th>
    <th>05-02-2019</th>
    <th>06-02-2019</th>
    <th>07-02-2019</th>
    <th>08-02-2019</th>
    <th>09-02-2019</th>
 </tr>
<tr>
    <td>01-02-2019</td>
    <td>02-02-2019</td>
    <td></td>
    <td></td>
    <td>05-02-2019</td>
    <td></td>
    <td></td>
    <td>08-02-2019</td>
    <td>09-02-2019</td>.......<td></td>
 </tr>

 </table>
$monthdays=28;
$listmonthdisplay=[
"0"=>"01-02-2019",
"1"=>"02-02-2019",
"2"=>"03-02-2019",
"3"=>"04-02-2019",
"4"=>"05-02-2019", ............"28"=>"05-02-2019"
]
$employeeDetail=[
“0”=>[“出席日期”=>“2019年2月1日”],
“1”=>[“出席日期”=>“2019年2月2日”],
“2”=>[“出席日期”=>“2019年2月5日”],
“3”=>[“出席日期”=>“08-02-2019”],
“5”=>[“出席日期”=>“09-02-2019”]
]   

我编辑了它,现在正在运行。

<?php
$monthdays=28;
$listmonthdisplay=[
    "0"=>"01-02-2019",
    "1"=>"02-02-2019",
    "2"=>"03-02-2019",
    "3"=>"04-02-2019",
    "4"=>"05-02-2019",
    "5"=>"06-02-2019",
    "6"=>"07-02-2019",
    "7"=>"08-02-2019",
    "8"=>"09-02-2019",
    "9"=>"10-02-2019",
    "10"=>"11-02-2019",
    "11"=>"12-02-2019"
    ...
];
$employeeDetail=[
    "0"=>["attendence_date"=>"01-02-2019"],
    "1"=>["attendence_date"=>"02-02-2019"],
    "2"=>["attendence_date"=>"05-02-2019"],
    "3"=>["attendence_date"=>"08-02-2019"],
    "5"=>["attendence_date"=>"09-02-2019"]
];
$tmpArray = array_column($employeeDetail, 'attendence_date');
?>
<table>
    <tr>
        <?php 
        for($i=0;$i<$monthdays;$i++){ 
            echo "<th>".$listmonthdisplay[$i]."</th>";
        }
        ?>
    </tr>
    <tr>
        <?php 
        for($i=0;$i<$monthdays;$i++){
            echo "<td>";
            if(in_array($listmonthdisplay[$i], $tmpArray)){
                echo $listmonthdisplay[$i];
            }
            echo "</td>";
        }
        ?>
        </tr>
</table>
获取要打印的日期的一维数组

第二个是在$tmpArray中将条件更改为搜索日期

您的问题不清楚@DevendraCan您向我们展示了您的预期结果吗?@Siddharthasesunuri我已经添加了完整的代码。请检查并给我建议。@M.Hemant我已经添加了完整的代码。请检查并给我建议。得到与前一个(当前结果)相同的结果,我需要显示预期结果。填写您的代码,添加所有带键和值的数组变量@DevendraI已经添加了我的完整代码。请检查并给我建议。
$tmpArray = array_column($employeeDetail, 'attendence_date');