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

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

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

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

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

)

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

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

阅读全文

yum 安装redis5

更新yum源 # EPEL的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质...

阅读全文

nginx 解析php conf配置文件

本博客的nginx 配置文件 server { listen 80;#80和443端口同时监听 listen 443 ssl; server_name www.koukousky.com koukousky.com...

阅读全文

欢迎留言