Jump to content

Echoing array values from a function in a while loop?


knox203

Recommended Posts

Could someone tell me how I can list the values from this array? I want them to appear inside a drop down list... I can print out the array as a whole with print_r() but I need individual values. Thanks!

 

<?
/**
* Function used to find the dates of specific days between
* two different dates.  So, if you want to find all the
* mondays and all the wednesdays between 2 dates, this
* function is right for you.
*
* @param string $startDate e.g. 2007-01-31
* @param string $endDate e.g. 2007-12-31
* @param csv string $days e.g. 'Su,M,T,W,TH,F,S';
* @return array
*/

$postmonth = $_POST['month'];
$startDate = "2008-01-01";
$endDate = "2008-01-31";
$days = 'M';

function getDaysBetween($startDate, $endDate, $days)
{
    $days = explode(',', $days);
    $dates = array();
    foreach($days as $day)
    {
        $newDate = $startDate;
        switch ($day){
            case 'Sun':
                $day = 'Sun';
                break;
            case 'M':
                $day = 'Mon';
                break;
            case 'Tue':
                $day = 'Tue';
                break;
            case 'W':
                $day = 'Wed';
                break;
            case 'Thu':
                $day = 'Thu';
                break;
            case 'F';
                $day = 'Fri';
                break;
            case 'Sat':
                $day = 'Sat';
                break;
            default:
                continue 2;
        }
        $curtime = strtotime("next $day", strtotime($startDate));
        $endtime = strtotime($endDate);
        while($curtime <= $endtime)
        {
           $dates[] = date('Y-m-d', $curtime);
           $curtime = strtotime("next 2 $day", $curtime);
        }
    }

    $dates = array_unique($dates);
    sort($dates);
    return $dates;
}
$dates = getDaysBetween($startDate, $endDate, $days);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.