1

Would want to make php more interactive

Looking for a way to list result when there is only one day left Result: 1 day remaining

Else: Result: n days remaining

Partial Code

$daysleft = $date2->diff($date1);
echo $daysleft->format('%a days'),' remaining';
Ajaxcbcb
  • 167
  • 2
  • 4
  • 14
  • Possible duplicate of [pluralize in PHP](http://stackoverflow.com/questions/1534127/pluralize-in-php) – Aviram Feb 17 '16 at 13:39
  • @aviram not really. im slightly confused by the diff function within the array. was looking for a way to extract the date differences – Ajaxcbcb Feb 17 '16 at 13:44

1 Answers1

1

You can just manually generate your text:

$daysleft = $date2->diff($date1)->format('%a');
echo $daysleft.' '.($daysleft == 1 ? 'day' : 'days').' remaining';

For this simple use case, this should be the best approach...

DerVO
  • 3,679
  • 1
  • 23
  • 27