mercredi 8 janvier 2020

How can I group days of week In the the below format in PHP/Laravel

I have computed an below provided array using the below query :

$combining_time_with_days = [];
foreach($scheduleStrings as $schedule => $scheduleString){ // $schedule = 9:00 am-11:00 am && $scheduleString = [0 => "Mon - Wed" ,1 => "Fri - Sat"]
   foreach($scheduleString as $key => $values){ // $key = 0 , 1, 2  && $value = "Mon - Wed" , "Fri - Sat"
         $combining_time_with_days[$values][] = $schedule ;
     }
}
[
  "Mon - Wed" => [
    0 => "9:00 am - 11:00 am"
    1 => "4:00 pm - 6:00 pm"
  ]
  "Fri - Sat" => [
    0 => "9:00 am - 11:00 am"
  ]
  "Mon" =>  [
    0 => "7:00 pm - 9:00 pm"
  ]
]

What I want to achieve is the below array :

[
  'Mon - Wed,Fri-Sat' : [
       0 =>  '9:00 am - 11:00 am'
    ],
  'Mon - Wed': [
       0 =>  "4:00 pm - 6:00 pm"
    ],
  'Mon': [
       0 => "7:00 pm - 9:00 pm"
    ]

]

I have tried many methods but fail to achieve it. It will be very helpful if anyone tries to help me in this code.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire