lundi 7 août 2017

display tr tags based on first array count and compare with second array in PHP

I have two arrays. I want to display the tr tag based on the count of $daterange and inside this, I need to check the date value with the second array date value.

First array :

$daterange = ['01/10/2017','02/10/2017','03/10/2017','04/10/2017','05/10/2017'];

Second array :

$job = [0 => ['id' =>1,'date' => '03/10/2017'],
        1 => ['id' =>2,'date' => '12/10/2017'],
        2 => ['id' =>3,'date' => '14/10/2017'],
        3 => ['id' =>4,'date' => '13/10/2017'],
        4 => ['id' =>5,'date' => '03/10/2017'],
        5 => ['id' =>6,'date' => '04/10/2017'],
        6 => ['id' =>7,'date' => '05/10/2017'],
        7 => ['id' =>8,'date' => '01/10/2017']
    ];

Html code :

<table>
<?php foreach($daterange as $key=>$day)
{ 
?>
<tr>
<td>

    <?php foreach($job as $jdata){
    if(($day->format('Y-m-d') == ($jdata->date)) {
    ?>
    <input type="radio" checked class="radio-check" name="date" value="">
    <?php
    } else {
    ?>
    <input type="radio"  class="radio-check" name="date" value="">
    <?php
    }
    ?>
</td>
</tr>
<?php
}
?>
</table>

But tr tag is displayed 8 times based on second array count.

How do I display tr 5 times, which is the count of the first array, and compare the date inside with the second array?




Aucun commentaire:

Enregistrer un commentaire