Home  >  Article  >  类库下载  >  Some commonly used date array sorting in PHP

Some commonly used date array sorting in PHP

高洛峰
高洛峰Original
2016-10-20 14:49:471636browse

In the process of developing the project, the website requires the input of some dates, such as the current year, month and day. Here are some arrays I have compiled for you that are used daily to obtain date and time.


Get the year from the beginning to the present

In the process of developing the project, the website requires the input of some dates, such as the year, month and day to date. Here are some daily uses that I have compiled for you. Array of datetimes.


Get the year from the beginning to the present

function yearArray(){
    $tody = getdate();
    $todyYear = $tody['year'];
    $startYear = 1900-1;
    $i = 1;
    for($startYear; $startYear < $todyYear; $startYear++){
        $yearArr[$i] = $startYear+1;
        $i++;
    }
    return $yearArr;
}


Get the array of 12 months

function monthArray(){
    $monthArr = array(1,2,3,4,5,6,7,8,9,10,11,12);
    return $monthArr;
}

Get all the days of a month Array

function dayArray(){
    $dayArr = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
    return $dayArr;
}


Get the array from Monday to Sunday

function weekArr(){
    return  array(&#39;1&#39;=>&#39;星期一&#39;,&#39;2&#39;=>&#39;星期二&#39;,&#39;3&#39;=>&#39;星期三&#39;,&#39;4&#39;=>&#39;星期四&#39;,&#39;5&#39;=>&#39;星期五&#39;,&#39;6&#39;=>&#39;星期六&#39;,&#39;7&#39;=>&#39;星期日&#39;);


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more