Skip to content
Advertisement

PHP Generate day range

I am trying to generate the range of days, from 1 to 28, with the English ordinal suffix for the day of the month. For example: 1st of month, 2nd of month

JavaScript

Output:

JavaScript

What am I doing wrong..?

Advertisement

Answer

Try this, it uses the contextual date functionality of ‘+1 day’ etc to register your integer as a day 🙂

To answer your second question – as in what you’re doing wrong – you’re passing an integer to a function that expects a string.

JavaScript

Output:

JavaScript

Edit:
To remove the 0s, you can use ltrim() like this:

JavaScript

Which will give you an output like this

JavaScript

Edit 2: Fixed it. Props to MLF for noticing the mistake.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement