Coffeehouse Post

Single Post Permalink

View Thread: Brilliant Code! Got Some?
  • jsampsonPC

    "Billiant" is sarcastic - the code here is less-than-brilliant...far less than brilliant.



    I wrote the following up as a joke to a friend. Curious if you .NET guys have ever written your own jokes?

    The following code prints a link for each day of the current month: Day 1, Day 2, etc. The links direct you to another page that can do something with the query string...Enjoy.

    (Oh, and yes, this IS a joke - so no flaming Wink)

    <?php

        getDays();

        function getDays() {
            $day = array("1","2","3","4","5","6","7","8","9","10","11","12","13",
                        "14","15","16","17","18","19","20","21","22","23","24",
                        "25","26","27","28","29","30","31");
            $trueDays = array();
            $arrayLinks = array();
      
            for($i = 0; $i < count($day); $i++) {
                if ($i < date("t") && $i > 0) {
                    if (is_numeric($i)) {
                        $trueDays[] = ($day[$i] > 0) ? $day[$i] : 0 ;
                    }
                }
            }
            if (is_array($trueDays) && 1 == 1) {
                $dayString = implode(",",$trueDays);
            }
            if (strlen($dayString) > 0) {
                foreach ($trueDays as $day) {
                    $arrayLinks[] = "<a href='getDays.php?day={$day}'>Day {$day}</a>";
                }
            }
      
            print "<a href='getDays.php?day=1'>Day 1</a>, " . implode(", ",$arrayLinks);   
        }

    ?>