sql
html
php
xml
database
ruby-on-rails
visual-studio
multithreading
eclipse
silverlight
flash
html5
algorithm
oracle
cocoa
apache
mvc
api
postgresql
dom
Make the Array Keys to Ints and compare them with date('n') (n stands for month without a prefix zero)
foreach($months as $month => $monthtitle): if ((int)$month >= (int)date('n')){ echo '<li title="'.$monthtitle.'" rel="'.$month.'"><a href="#" title="'.$monthtitle.'">'.$monthtitle.'</a></li>'; } endforeach;
You will need to check what is right now by using date() function. Specifically, the m parameter. To do that, you need to change this line:
date()
m
if ($month == '2'){
into:
if ($month >= date('m')){
I think something like this can get you started:
<?php $months = array('1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April', '5' => 'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September', '10' => 'October', '11' => 'November', '12' => 'December'); echo '<li><a class="by_month"></a><ul class="monthby" name="monthby">'; $a = date('n',time()); // current month (numeric) for($i = $a; $i <= 12; $i++){ echo '<li title="'.$months[$i].'" rel="'.$months[$i].'"><a href="#" title="'.$months[$i].'">'.$months[$i].'</a></li>'; } echo '</ul></li>';
I would consider using the built in date function so you don't have to list the Months out manually in your code. Then I might use the mktime function to convert the months to timestamps and compare them based on that. I've put some code below and here is a link to a codepad.
$currentMonth = 2; $currentTime = mktime(0, 0, 0, $currentMonth, 1, 2012); for ($i = 1; $i <= 12; $i++) { $iTime = mktime(0, 0, 0, $i, 1, 2012); if ($iTime >= $currentTime) { $monthTitle = date('F', $iTime); echo '<li title="' . $monthTitle . '" rel="' . $i . '"><a href="#" title="' . $monthTitle . '">' . $monthTitle . '</a></li>'; } }