php

安装Composer http://pkg.phpcomposer.com/#how-to-install-composer

php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php composer-setup.php
php -r "unlink('composer-setup.php');"

#linux
sudo mv composer.phar /usr/local/bin/composer
composer selfupdate

在非laravel环境用eloquent

https://github.com/laracasts/Eloquent-Outside-of-Laravel
https://vkbansal.me/blog/using-eloquent-outside-laravel/

出现 class pagination not exist,用不了

生成所有星期六星期日

//date_default_timezone_set('PRC');
$begin  = new DateTime('2010-01-01');
$end    = new DateTime('2018-12-31');
while ($begin <= $end) // Loop will work begin to the end date 
{
    //if($begin->format("D") == "Sun") //Check that the day is Sunday here
    if($begin->format("D") == "Sat")
    {
        $date = $begin->format("Y-m-d");
        $year = $begin -> format('Y');
        $month = $begin -> format('m');
        $url = "http://www.my903.tk/wp-content/uploads/{$year}/{$month}/sd-PlayToy".$date.".mp3?_=3";
        echo $url;
        echo "<br>";
    }

    $begin->modify('+1 day');
}

按时间倒序排序数据

    $arr = array(
        0 => array('dateline' => 1),
        1 => array('dateline' => 2),
    )

   //按时间倒序排序数据
    usort($arr, function($a, $b) {
        return $b['dateline'] - $a['dateline'];
    });

自然排序二维数组

https://stackoverflow.com/questions/10484607/php-sort-array-alphabetically-using-a-subarray-value


$arr = array(
0 => array('name' => 'a'),
1 => array('name' => 'z'),
);
usort($arr, function($a, $b) {
    return strcmp($a['name'], $b['name']);
});