I'd like to start off by saying thank you for taking the time to read this post. I hope that someone will be kind enough to help me as I am just starting to learn PHP. Please forgive me if I do not use the correct terminology to describe my issue.
I'm having an issue sorting my array.
My array looks like this:
<?php
$rooms = array(
strtotime('next monday')=>array('day'=>'monday', 'abbrev'=>'Mon'),
strtotime('next tuesday')=>array('day'=>'tuesday', 'abbrev'=>'Tue'),
strtotime('next wednesday')=>array('day'=>'wednesday', 'abbrev'=>'Wed'),
strtotime('next thursday')=>array('day'=>'thursday', 'abbrev'=>'Thu'),
strtotime('next friday')=>array('day'=>'friday', 'abbrev'=>'Fri'),
strtotime('next saturday')=>array('day'=>'saturday', 'abbrev'=>'Sat'),
strtotime('next sunday')=>array('day'=>'sunday', 'abbrev'=>'Sun'));
ksort($rooms);
foreach($rooms as $room_timestamp=>$room_info) {
if (time() > strtotime($room_info['day'])) {
print ($form->checkBox($model,'space_'.$room_info['day'], array('value' => strtotime($room_info['day']))) . $form->labelEx($model,$room_info['abbrev'].' ' . date('n/j', strtotime($room_info['day']))) . '<br />');
} else {
print ($form->checkBox($model,'space_'.$room_info['day'], array('value' => strtotime('next '.$room_info['day']))) . $form->labelEx($model,$room_info['abbrev'].' ' . date('n/j', strtotime('next '.$room_info['day']))) . '<br />');
}
}
echo "<pre>".print_r($rooms,1)."</pre>";
?>
And it is outputting the checkboxes in this order:
Mon 6/3
Tue 6/4
Wed 6/5
Thu 6/6
Fri 6/7
Sat 6/8
Sun 6/2
I'm trying to get today (in this case Sun 6/2) to show first, and then the next 6 days to show in order.
When I use print_r to display the raw output, it looks like this:
Array ( [1370239200] => Array ( [day] => monday [abbrev] => Mon ) [1370325600] => Array ( [day] => tuesday [abbrev] => Tue ) [1370412000] => Array ( [day] => wednesday [abbrev] => Wed ) [1370498400] => Array ( [day] => thursday [abbrev] => Thu ) [1370584800] => Array ( [day] => friday [abbrev] => Fri ) [1370671200] => Array ( [day] => saturday [abbrev] => Sat ) [1370757600] => Array ( [day] => sunday [abbrev] => Sun ) )
Sunday is showing a larger time stamp than the other days, is this because it is somehow outputting next Sunday's time stamp instead of today's time stamp?
Initially I was creating the checkboxes and labels using two if/else statements for each day. Unable to sort them this way I attempted to create an array which is what I am now having trouble with.
My original code (this example is for Tuesday) looked like this:
<?php
if (time() > strtotime('tuesday'))
{
echo $form->checkBox($model,'space_tuesday', array('value' => strtotime('tuesday')));
}
else
{
echo $form->checkBox($model,'space_tuesday', array('value' => strtotime('next tuesday')));
}
?>
<?php
if (time() > strtotime('tuesday'))
{
echo $form->labelEx($model,'Tues ' . date('n/j', strtotime('tuesday')));
}
else
{
echo $form->labelEx($model,'Tues ' . date('n/j', strtotime('next tuesday')));
}
?>
Is there a better way to create an array to achieve this and sort in the correct order? Am I missing something simple with the array I've already created?
Any help that you could provide would be greatly appreciated.
Thank you.