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

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

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

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

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

)

php-rdkafka测试笔记

参考:https://learnku.com/articles/15176/laravel-implementation-of-kafka-message-push-and-receive-processing 安装 安装librdkafka 库 git clone https...

阅读全文

推荐一个好用的php日志类库,monolog/monolog

github仓库地址 官方文档: https://github.com/Seldaek/monolog/blob/main/doc/01-usage.md 安装 $ composer require monolog/monolog 使用方法 <?php us...

阅读全文

一个好用的php id加密解密类,适用于隐藏用户真实id。hashids

效果 <?php use Hashids\Hashids; $hashids = new Hashids(); // no padding $hashids->encode(1); #结果 jR #指定返回10个字符长度的加密串 $hashids...

阅读全文

欢迎留言