duanpu8830 2015-07-08 14:27
浏览 20

根据条件显示数组值

I have this array

$array = array(
          date => '2015-07-08',
          title => 'Sample' 
          );

And this is my script for calendar

$calendar = mktime(0,0,0,date("n"),1,date("Y"));
    $getprevdays = mktime(0,0,0,date("n")-1,1,date("Y"));

    $thisday = getdate($calendar);
    $startday = $thisday['wday'];
    $maxday = date("t", $calendar);

    $year = date("Y", $calendar);
    $month = date("n", $calendar);
    echo "<table border='1'>";

        echo "<tr>";
            echo "<th>Sunday</th>";
            echo "<th>Monday</th>";
            echo "<th>Tuesday</th>";
            echo "<th>Wednesday</th>";
            echo "<th>Thursday</th>";
            echo "<th>Friday</th>";
            echo "<th>Saturday</th>";

        echo "</tr>";

        for($i=0;$i<($maxday+$startday);$i++){

            if(($i%7)==0) echo "<tr>";
            if($i<$startday) echo "<td></td>";
            else{
                echo "<td>" . ($i - $startday + 1);

                 foreach($array $as $arr){
                     if(date('d', strtotime($arr['date']) == ($i - $startday + 1)){
                         echo $arr['title']
                     }

                 }  

                echo "</td>"; //This is where to display data
            }
            if(($i%6)==1) "</tr>";

        }


    echo "</table>";

Im trying to display the title based on the date given.

In my script, It display the calendar of the current month and produced table like data. In each cell, displays the current day of the month and it can also contain data. I tried using this codes,

foreach($array $as $arr){
      if(date('d', strtotime($arr['date']) == ($i - $startday + 1)){
           echo $arr['title']
      }

}

($i - $startday + 1) this codes display the number of day of the month, so if the day of the date is the same, that is when it will echo the title. Any idea on how can I achieve this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭