monday tuesday wednesday 3d 3e monday wednesday php

Solutions on MaxInterview for monday tuesday wednesday 3d 3e monday wednesday php by the best coders in the world

showing results for - "monday tuesday wednesday 3d 3e monday wednesday php"
Ricardo
12 Nov 2017
1function weekendDaysToString($days, $lang = 'en') {
2    $and = array('pt'=>'e', 'en'=>'and');
3    $strWeek = array(     // config with more langs!
4        'pt'=>array("Segunda", "Terça", "Quarta", "Quinta", "Sexta",
5            "Sábado", "Domingo"),
6        'en'=> array("Monday", "Tuesday", "Wednesday", "Thursday",
7            "Friday", "Saturday", "Sunday")
8    );
9    $days = array_unique($days);
10    sort($days);
11    $seq = preg_replace_callback(  // Split sequence by ",":
12        '/0246|024|025|026|135|146|246|02|03|04|05|06|13|14|15|16|24|25|26|35|36|46/',
13        function ($m) { return join( ',' , str_split($m[0]) ); },
14        implode('',$days)
15    );
16    // split two or more days by "-":
17    $seq = preg_replace('/(\d)\d*(\d)/', '$1-$2', $seq);
18    $a = explode(',',$seq);
19    $last = array_pop($a);
20    $n = count($a);
21    // Formatting and translating:
22    $seq = $n? implode(", ",$a): $last;
23    if ($last && $n) $seq = "$seq $and[$lang] $last";
24    return preg_replace_callback(
25        '/\d/',
26        static function ($m) use (&$strWeek,$lang) {
27            return $strWeek[$lang][$m[0]];
28        },
29        $seq
30    );
31}
32
33
34
35############## TESTINGS #################
36print "\n".weekNumbers_toStr(array(6,1,2,3,6),'en'); // corrects order and dups
37print "\n".weekNumbers_toStr(array(0,1,2,3,6));      // Monday-Thursday and Sunday
38
39print "\n".weekNumbers_toStr(array(3,4,6),'pt');  // Quinta-Sexta e Domingo
40print "\n".weekNumbers_toStr(array(3,4,6));       // Thursday-Friday and Sunday
41
42print "\n".weekNumbers_toStr(array(2,3,4,6));  // Wednesday-Friday and Sunday
43print "\n".weekNumbers_toStr(array(3,5));      // Thursday and Saturday
44print "\n".weekNumbers_toStr(array(0,2,4,6));  // Monday, Wednesday, Friday and Sunday
45print "\n".weekNumbers_toStr(array(0));        // Monday
46print "\n".weekNumbers_toStr(array());         // (nothing)