I've asked a question here on combining days where the opening hours of a shop are similar
Combine days where opening hours are similar
Now I need some help in doing the opposite: Taking strings that contains the combined days and splitting them up into individual days, and store them in an array in order of the day (Mon first, Sun last).
For example, here is a set of strings that needs to be converted (exact same format):
Mon-Fri 11 am - 7:30 pm
Sat 11 am - 6 pm
Both strings need to be combined together and converted to this array:
array[0] = "11am - 7:30pm"
array[1] = "11am - 7:30pm"
array[2] = "11am - 7:30pm"
array[3] = "11am - 7:30pm"
array[4] = "11am - 7:30pm"
array[5] = "11am - 6pm"
array[6] = "" // Blank value if the day Sunday is not in the set of strings that needs conversion
// ideally it should be an associative array, ie. array['mon'] = "11am - 7:30pm"
Btw, I'm using Codeigniter PHP framework and jQuery.
UPDATE:
I now have to split this string of text containing commas!
Mon 9 pm - 1 am
Tue-Wed, Sun 7:30 pm - 1 am
Thu-Sat 7:30 pm - 2 am
Resulting array:
Array
(
[Mon] => 9 pm - 1 am
[Tue] =>
[Wed] =>
[Thu] => 7:30 pm - 2 am
[Fri] => 7:30 pm - 2 am
[Sat] => 7:30 pm - 2 am
[Sun] =>
)
Looks like I have to split Tue-Wed from Sun, from
Tue-Wed, Sun 7:30 pm - 1 am
to
Tue-Wed 7:30 pm - 1 am
Sun 7:30 pm - 1 am
@Khattam: This chunk of timings:
Mon 9 pm - 1 am
Tue-Wed, Sun 7:30 pm - 1 am
Thu-Sat 7:30 pm - 2 am
gives:
Array
(
[Mon] => 9 pm - 1 am
[Tue] => 7:30 pm - 1 am
[Wed] => 7:30 pm - 1 am
[Thu] => 7:30 pm - 2 am
[Fri] => 7:30 pm - 2 am
[Sat] => 7:30 pm - 2 am
[Sun] =>
[
] =>
)
Mon-Tue, Mon-Wed, Mon-Thu, Mon-Fri, Mon-Sat, Mon-Sun, Tue-Wed, Tue-Thu...etc-and then approaching the problem.