对数组值进行排序除了我可以利用老师教的各种排序法外,我们的php就直接给你一个函数rsort()函数,用法非常简单,但只适合于数组。
rsort(array,sorttype)
参数 描述
array 必需。输入的数组。
sorttype 可选,规定如何排列数组的值,可能的值:
SORT_REGULAR – 默认,以它们原来的类型进行处理,不改变类型
SORT_NUMERIC – 把值作为数字来处理
SORT_STRING – 把值作为字符串来处理
SORT_LOCALE_STRING – 把值作为字符串来处理,基于本地设置.
代码如下:
- <?php
- $my_array = array("a" => "Dog", "b" => "Cat", "c" => "Horse");
- rsort($my_array);
- print_r($my_array);
- ?>
- //输出:
- Array
- (
- [0] => Horse
- [1] => Dog
- [2] => Cat
- )
其它参考,代码如下:
- $data[] = array('volume' => 67, 'edition' => 2);
- $data[] = array('volume' => 86, 'edition' => 1);
- $data[] = array('volume' => 85, 'edition' => 6);
- $data[] = array('volume' => 98, 'edition' => 2);
- $data[] = array('volume' => 86, 'edition' => 6);
- $data[] = array('volume' => 67, 'edition' => 7);
本例中将把 volume 降序排列,把 edition 升序排列,现在有了包含有行的数组,但是 array_multisort() 需要一个包含列的数组,因此用以下代码来取得列,然后排序。
取得列的列表,代码如下:
- foreach ($data as $key => $row) {
- $volume[$key] = $row['volume'];
- $edition[$key] = $row['edition'];
- }
- // 将数据根据 volume 降序排列,根据 edition 升序排列
- // 把 $data 作为最后一个参数,以通用键排序
- array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
数据集合现在排好序了,结果如下:
- volume | edition
- ——-+——–
- 98 | 2
- 86 | 1
- 86 | 6
- 85 | 6
- 67 | 2
- 67 | 7
实际上真正在排序的时候还有很多方法可以使用,比如php的array数组自带的 arsort(),asort(),ksort(),krsort(),natsort(),natcasesort(),rsort(),usort(),array_multisort() 和 uksort()。
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php数组之数组的元素值进行降序排序rsort()函数
波比源码 » php数组之数组的元素值进行降序排序rsort()函数
purchase levaquin generic order levaquin 250mg for sale
ampicillin online buy acillin canada erythromycin 500mg usa
order anastrozole generic arimidex cheap sildenafil for men over 50
buy deltasone 40mg for sale buy viagra generic viagra price
buy sertraline 100mg without prescription Buy generic viagra buy viagra 50mg generic
tadalafil 10mg sale prozac 20mg canada viagra ca
provigil cheap online pharmacy cost ivermectin
brand tadalafil cialis pharmacy viagra price
furosemide for sale online buy furosemide 40mg online plaquenil 200mg without prescription
chloroquine usa chloroquine 250mg tablet order baricitinib 2mg pills
amlodipine 5mg uk buy amlodipine 5mg without prescription tadalafil 40mg brand
buy clozaril 50mg sale dexamethasone us dexamethasone 0,5 mg oral
purchase prilosec sale order omeprazole 20mg pills free welcome spins no deposit
order clomid 50mg for sale albuterol drug online blackjack live dealer
tadalafil 5mg cost tadalafil 20mg viagra 100mg pill
order generic allopurinol cost zetia 10mg purchase ezetimibe for sale
order motilium online buy motilium pills order flexeril generic
buy tadalafil 5mg buy ampicillin for sale ciprofloxacin 500mg us
cheap zocor simvastatin 10mg canada buy generic propecia 1mg
order metronidazole 200mg pill cheap augmentin bactrim brand
order fluconazole 100mg generic generic viagra 100mg sildenafil 100mg tablet
cialis overnight shipping usa tadalafil 5mg over the counter viagra pharmacy
generic viagra 50mg buy viagra 50mg online cheap buy tadalafil 40mg for sale
write research paper for me college paper help ivermectin cost australia
purchase sildalis online cheap estrace us lamotrigine 50mg over the counter
deltasone 40mg generic cheap amoxil sale buy amoxil online cheap
free blackjack play real poker online order modafinil 100mg sale
furosemide 100mg generic lasix drug hydroxychloroquine 200mg tablet
generic deltasone 5mg order mebendazole 100mg pills purchase mebendazole
tadacip order buy voltaren 50mg for sale indocin 75mg cost
buy proventil 100 mcg without prescription buy cipro online cheap order cipro 500mg online
purchase actos generic cheap viagra for sale sildenafil professional
cialis 10mg over the counter online gambling money sports gambling online gambling real money
tadalafil 20mg us Buy discount cialis buy cialis generic
ivermectin 3 mg tablet dosage dapsone 100mg ca cheap avlosulfon 100mg
adalat cheap adalat 10mg ca fexofenadine 180mg sale
assignments for sale buy cheap essays online sulfasalazine 500mg oral
benicar online order divalproex 250mg generic depakote 250mg pill
order asacol 400mg online cheap asacol 400mg ca buy avapro 300mg without prescription
order amoxil 1000mg pill amoxicillin generic price of ivermectin liquid
order priligy 30mg domperidone brand order domperidone online cheap
generic indocin 50mg indomethacin us cenforce buy online
tadalafil 10mg pill tadalafil online trimox canada
minocin 100mg tablet order minocycline 50mg without prescription generic terazosin
oral clomiphene 50mg generic atorvastatin 10mg oral prednisolone
best ed pills cost pregabalin 75mg finasteride 5mg without prescription
accutane 40mg price order ampicillin 250mg generic buy ampicillin online cheap
stromectol tablets 3 mg medication for ed deltasone 10mg drug
accutane online buy buy generic zithromax generic zithromax