以前我们有讲过各种php数组排序的方法,同时php也提供了大量的数据排序函数,sort(),asort(),arsort()等,下面我来给各位同学介绍二维数组按指定的键值排序的方法,具体实例代码如下:
- /*二维数组按指定的键值排序*/
- function array_sort($array,$keys,$type='asc'){
- if(!isset($array) || !is_array($array) || emptyempty($array)){
- return '';
- }
- if(!isset($keys) || trim($keys)==''){
- return '';
- }
- if(!isset($type) || $type=='' || !in_array(strtolower($type),array('asc','desc'))){
- return '';
- }
- $keysvalue=array();
- foreach($array as $key=>$val){
- $val[$keys] = str_replace('-','',$val[$keys]);
- $val[$keys] = str_replace(' ','',$val[$keys]);
- $val[$keys] = str_replace(':','',$val[$keys]);
- $keysvalue[] =$val[$keys];
- }
- asort($keysvalue); //key值排序
- reset($keysvalue); //指针重新指向数组第一个
- foreach($keysvalue as $key=>$vals) {
- $keysort[] = $key;
- }
- $keysvalue = array();
- $count=count($keysort);
- if(strtolower($type) != 'asc'){
- for($i=$count-1; $i>=0; $i–) {
- $keysvalue[] = $array[$keysort[$i]];
- }
- }else{
- for($i=0; $i<$count; $i++){
- $keysvalue[] = $array[$keysort[$i]];
- }
- }
- return $keysvalue;
- }
使用方法,代码如下:
- $a=array(
- 1=>array(
- id=>1,
- price=>'79',
- ),
- 2=>array(
- id=>1,
- price=>'68',
- ),
- );
就使用:array_sort($a,'price');
php数组排序函数
sort (&$arr[,fruits]) 对数组进行从低到高排序,并赋予新的键名 返回bool
rsort (&$arr[,fruits]) 对数组进行逆向排序,并赋予新的键名
asort (&$arr[,fruits]) 对数组进行排序,并保持索引不变
arsort(&$arr[,fruits]) 对数组进行逆向排序,并保持索引不变
ksort (&$arr [,fruits]) 对数组按照键名进行排序
krsort(&$arr [,fruits]) 对组数按照键名进行逆向排序
natsort(&$arr) 对数组键值进行‘自然排序法’按照长度,字母排序等
natcasesort(&$arr) 对数组进行不区分大小写的‘自然排名’
usort (&$arr,cmp_function ) 用户自定义函数对一个数组进行排序,重新排列键名
uksort (&$arr,cmp_function ) 用户自定义函数对一个数组进行键名排序
uasort (&$arr,cmp_function) 用户自定义函数对数组进行排序 并保持索引不变
array_multisort($arr,mixed) 第二个参数是可以根据值改变排序行为
SORT_REGULAR 正常比较单元 SORT_NUMERIC 单元被作为数字来比较
SORT_STRING 单元被作为字符串来比较 SROT_LOCALE_STRING 根据当前的local 设置来把单元当做字符串比较
波比源码 » php 二维数组按指定的键值排序
order levofloxacin 250mg online levofloxacin canada
order cialis pills cost cialis 20mg buy sildenafil without prescription
original tadalafil rezeptfrei sicher kaufen sildenafil 200mg kaufen sildenafil 100mg generika
ramipril 10mg without prescription buy generic ramipril azelastine 10ml brand
lasix 40mg pill order doxycycline online plaquenil 200mg without prescription
order chloroquine pills baricitinib medication olumiant 2mg oral
purchase motilium pills motilium over the counter cyclobenzaprine generic
purchase sildalis sale estrace cost lamictal pills
order sildenafil 50mg pills sildenafil 100mg tablets buy cialis for sale
buy generic zithromax prednisolone 20mg cost neurontin 100mg pill
online gambling games planning poker online buy modafinil 200mg online
buy prednisone generic buy prazosin 1mg vermox pill
naprosyn 500mg brand naproxen 500mg oral prevacid cheap
order proventil 100 mcg pill buy proventil for sale ciprofloxacin pills
buy singulair 5mg generic cheap viagra sale viagra 100mg over the counter
parx casino online online casino for real money casino online usa
cost adalat 30mg buy allegra 120mg online fexofenadine 180mg pills
poker online for real money best online poker sites for real money good academic writing
order asacol 800mg generic astelin 10ml brand buy avapro 150mg sale
order acetazolamide generic brand azathioprine 25mg brand imuran
temovate usa buy clobetasol online amiodarone price
order lanoxin sale lanoxin 250 mg uk purchase molnupiravir for sale
alendronate online motrin 400mg ca motrin usa
buy pamelor 25 mg pills paxil 20mg for sale paroxetine medication
indomethacin 75mg over the counter buy indomethacin 50mg capsule buy cenforce
cost modafinil 100mg generic promethazine 25mg phenergan generic
erectile dysfunction pills over the counter buy proscar 1mg pill finasteride 1mg pill
zofran 8mg price cost amoxil 250mg bactrim without prescription
brand accutane 10mg zithromax 250mg us order azithromycin 250mg for sale
purchase avodart for sale purchase xenical for sale orlistat 120mg generic
buy generic azathioprine 25mg order naprosyn 500mg generic order naproxen 250mg for sale
buy generic cefdinir 300mg buy prevacid without prescription protonix us
dapsone buy online cheap atenolol buy tenormin paypal
viagra ca best cialis price order cialis 10mg sale
purchase promethazine for sale cialis samples buy tadalafil 10mg generic
order zetia online sumycin online methotrexate uk
cenforce 50mg uk cenforce tablet purchase glucophage for sale
buy escitalopram 10mg online cheap escitalopram 10mg canada naltrexone 50 mg usa
femara 2.5 mg us buy femara without a prescription sildenafil 50mg for sale
cialis overnight hims ed pills the best ed pill
buy cialis 20mg without prescription generic tadalafil next day delivery ed solutions
ivermectin eye drops order generic isotretinoin 40mg order accutane 10mg sale
amoxicillin where to buy buy prednisolone 20mg online prednisolone 5mg usa
order isotretinoin without prescription buy isotretinoin cheap order azithromycin 500mg
order albuterol for sale buy augmentin no prescription synthroid usa
serophene order online how to get clomid without a prescription hydroxychloroquine 400mg us
order tenormin 50mg sale methylprednisolone 8mg for sale femara pills
buy levothroid order levothroid generic levitra 20mg without prescription
biltricide price order periactin 4mg for sale buy periactin 4 mg pills
buy lyrica 150mg pills pregabalin over the counter brand dapoxetine 60mg
methotrexate 2.5mg uk coumadin 5mg drug order metoclopramide 20mg generic
order losartan 50mg sale purchase cozaar pills oral topiramate 100mg
tetracycline over the counter sumycin over the counter buy generic baclofen 10mg
cheap toradol ketorolac pill order inderal 20mg generic
oral ranitidine 300mg buy celebrex 200mg without prescription celebrex 200mg cost
betamethasone 20gm creams purchase betnovate generic itraconazole 100 mg ca
starlix 120mg canada candesartan online cheap candesartan
order zocor sale sildenafil brand sildenafil citrate 50mg
order carbamazepine 200mg pill buy ciprofloxacin 500mg pill lincocin 500 mg drug
brand tadalafil 5mg Order viagra online sildenafil citrate 50mg
duricef 500mg generic combivir where to buy finasteride 5mg us
fluconazole price buy acillin sale oral cipro
buy flagyl generic buy cephalexin 250mg buy generic cephalexin for sale
cleocin 300mg pill best natural ed pills ed pills for sale
avana 100mg without prescription buy avanafil 200mg generic buy diclofenac 50mg online cheap
suhagra 100mg pills buy sildenafil 50mg pill sildenafil overnight
buy minocin hytrin 1mg brand how to buy pioglitazone
order isotretinoin 20mg generic cheap amoxicillin online azithromycin 250mg ca
buy generic lasix 100mg buy ventolin 2mg pills buy generic ventolin 2mg
buy levitra 20mg order generic levitra 10mg buy generic plaquenil online
buy temovate for sale temovate generic amiodarone 200mg usa
buy coreg 6.25mg generic buy carvedilol generic order chloroquine 250mg
baricitinib 2mg usa buy atorvastatin 80mg for sale atorvastatin 20mg over the counter
where can i buy albuterol buy albuterol 100mcg generic phenazopyridine drug
buy norvasc 5mg generic buy omeprazole 10mg for sale buy generic prilosec over the counter
buy lopressor 50mg generic tenormin 50mg brand how to get medrol without a prescription
order rosuvastatin 10mg pills where to buy zetia without a prescription buy motilium 10mg
acillin drug order ampicillin 500mg generic metronidazole 200mg generic
buy generic septra for sale buy generic cephalexin 500mg cleocin online
erythromycin online buy purchase erythromycin pill order nolvadex 10mg pill
where to buy budesonide without a prescription budesonide online order careprost brand
topamax sale topiramate 100mg generic buy levaquin sale
cost aurogra 100mg sildalis oral buy estradiol generic
buy dutasteride without prescription zantac 150mg brand meloxicam 15mg cost
lamictal 200mg ca lamictal 50mg generic order prazosin without prescription
buy tadacip 20mg sale order indocin buy indocin pills
she advised him to come back at once example are google forms anonymou
molnunat 200mg generic cost naproxen 250mg buy cefdinir online cheap
best ed pills non prescription uk cialis sale order tadalafil 40mg for sale
essay writing service uk review college paper writing using an essay writing service reddit
generic terazosin 1mg buy terazosin without a prescription pfizer cialis
buy avapro 150mg generic clobetasol cheap order buspirone 5mg pills
ditropan 5mg cost oxybutynin 2.5mg price alendronate online order
generic acetaminophen 500mg buy generic panadol buy famotidine 20mg sale
buy prograf pills for sale tacrolimus 1mg cheap requip 1mg for sale
buy generic tinidazole for sale purchase tinidazole pill buy nebivolol 20mg generic
order rocaltrol pills buy generic tricor over the counter order tricor 160mg pills
buy trileptal generic urso 150mg for sale actigall cheap
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Seo Uzmani Umut Can Skype: By_uMuT@KRaLBenim.Com
how to buy seroquel buy zoloft 100mg online cheap brand lexapro 20mg
buy fluoxetine cheap buy femara 2.5 mg buy generic letrozole for sale
civil service mains essay question paper 2017 what to write a college essay about besht essay writing service
cost frumil 5mg cost clindamycin buy acivir cream
zebeta online buy cost lozol terramycin 250mg for sale