<?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
            748 views => 500
        )

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

    [2] => Array
        (
            [title] => 标题3
            748 views => 300
        )

    [3] => Array
        (
            [title] => 标题2
            748 views => 200
        )

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

)

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

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

阅读全文

php 解决超卖的几种方案(redis锁、mysql悲观锁)

1.创建商品和订单表模拟商品交易操作 fa_goods商品表,stock商品库存,test_order=订单表 2.添加一个测试商品数据(商品数量为150个) 测试并发购买的方法(gol...

阅读全文

centos8 yum安装php7.3

执行命令 $ yum install epel-release $ rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm $ dnf install -y https://rpms...

阅读全文

欢迎留言