php中数据排序可以用sort但如果要做到数组分组排序的话我们可以使用array_multisort函数或者使用多重复遍历来做,下面看一个例子。
PHP的数组,数组中的内容大致如下:
代码如下 | 复制代码 |
$list = array( |
为了方便表达,我把3列数字分别称为,ABC三列
需求:默认以A列排序为主,如果A列相同则以C列倒序排列相同的元素。B列其实没有参与排序,但是在实际运用中有用,所以我也写出来了。
方法一:
代码如下 | 复制代码 |
$a = $c = array(); |
方法二:
代码如下 | 复制代码 |
for($j=0;$j |
例子2
例如有下面的数据,从数据库里查出来的,是一个二维数组。
[0] => Array ( [trans_lang_id] => 1 [country_id] => 1 [trans_origin_id] => 1 [page_id] => 1 [trans_content] => test1
[1] => Array ( [trans_lang_id] => 2 [country_id] => 1 [trans_origin_id] => 2 [page_id] => 1 [trans_content] => test2
[2] => Array ( [trans_lang_id] => 3 [country_id] => 1 [trans_origin_id] => 3 [page_id] => 1 [trans_content] => test3
[3] => Array ( [trans_lang_id] => 4 [country_id] => 1 [trans_origin_id] => 4 [page_id] => 1 [trans_content] => test4
[4] => Array ( [trans_lang_id] => 6 [country_id] => 2 [trans_origin_id] => 1 [page_id] => 2 [trans_content] => test5
怎样按照country_id 和page_id分组,将里面的数据查分成多个数组?
也就是country_id和page_id相同的数据成为一个新数组。因为这样的数据会输出到同一个csv文件。
比如文件名为 zh_CN_1.csv。
代码如下 | 复制代码 |
Array Translates: CN_zh:Array ( foreach ($translates as $translate) { 这样的话输出的CSV就像下面的结构: |
每个csv里面可能有多条数据,就是那些国家语言以及page_id都相同的数据就放在同一个csv里

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
