PHP - bigktmbig/MyExperienceAlgorithm GitHub Wiki

=====================================================composer update 20191029 composer update --prefer-source

  • handle singgle or double quote in php to json: str_ireplace("'", "'", $string); and str_ireplace("\\", "\", $string); and str_ireplace('"', """, $string);

=====================2018/12/21

  • group data by column same value
  1. function array_group_by(array $arr, callable $key_selector) { $result = array(); foreach ($arr as $i) { $key = call_user_func($key_selector, $i); $result[$key][] = $i; }
    return $result; } $grouped = array_group_by($data, function($i){ return $i[0]; }); 2.$group = array();

foreach ( $array as $value ) { $group[$value['id']][] = $value; } ===========================================2018/12/21

  1. return current date to end date of month public function getListDays($sStartDate, $sEndDate){ $sStartDate = date("Y/m/d", strtotime($sStartDate));
    $sEndDate = date("Y/m/d", strtotime($sEndDate));

     $aDays[]      = $sStartDate;  
     $sCurrentDate = $sStartDate;  
    
     // While the current date is less than the end date  
     while($sCurrentDate < $sEndDate){  
         // Add a day to the current date  
         $sCurrentDate = date("Y/m/d", strtotime("+1 day", strtotime($sCurrentDate)));  
    
         // Add this new day to the aDays array  
         $aDays[] = $sCurrentDate;  
     }  
    
     return $aDays;  
    

    }

=============================================2018/12/26 strtotime $tmpDate = str_replace('/', '-', $datetime); $delta = strtotime('now') - strtotime($tmpDate); ======================================================2019/01/18 check user agent $iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad"); =====================================================2019/01/29 mergcells up 2 column in excel foreach ( $showCommentList as $comment ){ // if ($cur_col_t_6 == 'G') { $column_first_6 = $cur_col_t_6;

                                        for($i=1; $i <= 2; $i++) {
                                            $cur_col_g_6++;// show G, H, I, J, K ...
                                            $cur_col_g_now_6 = $cur_col_g_6;
                                            if ($i == 1) {
                                                $cur_col_t_6++; 
                                                $cur_col_t_6 = $cur_col_g_6;
                                            }
                                        }
                                        $cur_col_g_6 = $cur_col_g_now_6;
                                        $cur_col_t_6    = $cur_col_t_6;
                                        // rows excel 6
                                        $current_cells_6  = $column_first_6.$row_gcomment_label.':'.$cur_col_t_6.$row_gcomment_label;
                                    }else{
                                        $column_first_6 = $cur_col_g_6;

                                        for($i=1; $i <= 2; $i++) {
                                            $cur_col_g_6++;// show G, H, I, J, K ...
                                            $cur_col_g_now_6 = $cur_col_g_6;
                                            if ($i == 1) {
                                                $cur_col_t_6++; 
                                                $cur_col_t_6 = $cur_col_g_6;
                                            }
                                        }
                                        $cur_col_g_6 = $cur_col_g_now_6;
                                        $cur_col_t_6    = $cur_col_t_6;
                                        // rows excel 6
                                        $current_cells_6  = $column_first_6.$row_gcomment_label.':'.$cur_col_t_6.$row_gcomment_label;
                                    }
                                    $sheet->mergeCells($current_cells_6);
                                    $sheet->setCellValue($column_first_6.$row_gcomment_label, $comment);
                                }

==========================================2019/05/23 thêm 0 trước tháng <10 str_pad(11,2,"0",STR_PAD_LEFT);

==========================================2019/06/20 cắt chuỗi và thêm 0 trước time $startTime = substr(str_pad('830', 4, "0", STR_PAD_LEFT), -4, 2) .':' . substr(str_pad('830', 4, "0", STR_PAD_RIGHT), -2); $endTime = substr(str_pad('1730', 4, "0", STR_PAD_LEFT), -4, 2) .':' . substr(str_pad('1730', 4, "0", STR_PAD_RIGHT), -2); ============================================set cookie setcookie($name, $value, $expire, $path, $domain, $secure, $httponly )

======================================================== JP calendar <?php

function getDay($date) { return date('w', strtotime($date)); } $curYear = date("Y"); $curMonth = date("m");

$curMonth = 4; $days = array('日', '月', '火', '水', '木', '金', '土'); for ($i = 1; $i <= 10; $i++){ $day = getDay($curYear . '-' . $curMonth . '-' . $i); echo $days[$day]; ?> <?php } ?>

=============================================Get lasr date of month $lastDate = date('d', strtotime(date("Y-m-t", strtotime($curYear . '-' . $curMonth . '-15'))));

⚠️ **GitHub.com Fallback** ⚠️