<?php

$array = [
    [
        'title' => '标题5',
        'views' => 500
    ],
    [
        'title' => '标题3',
        'views' => 300
    ],
    [
        'title' => '标题2',
        'views' => 200
    ],
    [
        'title' => '标题4',
        'views' => 400
    ],
    [
        'title' => '标题1',
        'views' => 100
    ],
];

usort($array, function ($item1, $item2) {

    return $item1['views'] < $item2['views'];
});

print_r($array);
#result: 
Array
(
    [0] => Array
        (
            [title] => 标题5
            1,229 views => 500
        )

    [1] => Array
        (
            [title] => 标题4
            1,229 views => 400
        )

    [2] => Array
        (
            [title] => 标题3
            1,229 views => 300
        )

    [3] => Array
        (
            [title] => 标题2
            1,229 views => 200
        )

    [4] => Array
        (
            [title] => 标题1
            1,229 views => 100
        )

)

php实现redis延时队列

写了一个简单的类实现 使用方法 $class = new RedisDelayQueue(); $class->execute(); <?php namespace app\common\service; class RedisDelay { ...

阅读全文

php获取包含10w个手机号的txt文件(逗号隔开)

txt文件格式如下 13000000000,13000000005,13000000403,13001010129,13001010688,13001010838,13001016389,13001019538,13001030005,13001042700,13001047495...

阅读全文

php使用Carbon获取2个日期之间的日期

<?php use Carbon\CarbonPeriod; $period = CarbonPeriod::create('2018-06-14', '2018-06-20'); // Iterate over the period fore...

阅读全文

欢迎留言