Home php教程 PHP源码 二维数组的‘分组’排序

二维数组的‘分组’排序

May 25, 2016 pm 05:09 PM


$val){
				  asort($new[$key]);//分别对每一组的数据进行排序;
				  $tmp=$new[$key];//将排序后的数据赋值给一个临时数组;
				  $tmp[]=$key;//将原来数组的键值加入到临时数组的末尾,为后期的修改键值的步骤做准备;
				  $tmp2=$new[$key];
				  $a=array_shift($tmp2)*100;//将每一组的第一项(最小项)数据取出来,以aa组为例子,$a此时的值就为33;
                                  if(array_key_exists($a,$aa)){++$q_count;$a=$a+$q_count;}
				  $aa[$a]=$tmp;//新建一个数组,以$aa(比如33)为键值;
				  ksort($aa);//按照键值排序
		  }
		  foreach($aa as $key=>$val){//按照键值排序的数组,已经失去了原来的键值,比如aa/bb/cc/dd之类的,好在我们之前已经将键值存入了临时数组的末尾;
			  $b=array_pop($aa[$key]);//将键值取出来;
			  $bb[$b]=$aa[$key];//从新建立一个数组,使用之前的键值(aa/bb/cc)
		  }
		  return $bb;//返回
}
			
$c=arr_group_sort($new);    
print_r($new);//原数组;
print_r($c);//分组排序后的数组;
            ?>
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)