- sort:排序「值」,從小到大 (Sort an array)
$tempArray = array(5,8,1,2,7,6,3,4);
sort($tempArray);
#結果會是 1 2 3 4 5 6 7 8 - rsort:排序「值」,從大到小 (Sort an array in reverse order)
$tempArray = array(5,8,1,2,7,6,3,4);
rsort($tempArray);
#結果會是 8 7 6 5 4 3 2 1 - ksort:排序「Key」,從小到大 (Sort an array by key)
#這個例子要用key value的格式會比較好理解
$tempArray = array(
"b" => "Marry",
"c" => "Jack",
"a" => "Rich",
"d" => "Jason"
);
ksort($tempArray);
#結果會是 a => "Rich", b => "Marry", c => "Jack", d => "Jason"
#注意到了嗎?他是按照key來做排序,並不是按照值喔 - krsort:排序「Key」,從大到小 (Sort an array by key in reverse ordery)
$tempArray = array(
"b" => "Marry",
"c" => "Jack",
"a" => "Rich",
"d" => "Jason"
);
krsort($tempArray);
#結果會是 d => "Jason", c => "Jack", b => "Marry", a => "Rich"
#這是做key的反向排序 - asort:排序「值」,從大到小,且保留原本的index
(Sort an array and maintain index association)
這是什麼意思? asort跟sort很像,差別在sort之後會改變原本的index順序,而asort會保留原本的index
//比較sort 與 asort
$tempArray = array("e","h","a","b","g","f","c","d");
sort($tempArray);
#結果會是 0=>a, 1=>b, 2=>c, 3=>d, 4=>e, 5=>f, 6=>g, 7=>h
#index的順序是從0-7
//而asort會保留排序之前的index位置
$tempArray = array("e","h","a","b","g","f","c","d");
asort($tempArray);
#結果會是 2=>a, 3=>b, 6=>c, 7=>d, 0=>e, 5=>f, 4=>g, 1=>h
#index的順序是從就不是0-7了,變成 2 3 6 7 0 5 4 1 - arsort:排序「值」,從小到大,且保留原本的index
(Sort an array in reverse order and maintain index association)
$tempArray = array("e","h","a","b","g","f","c","d");
arsort($tempArray);
#結果會是 1=>h, 4=>g, 5=>f, 0=>e, 7=>d, 6=>c, 3=>b, 2=>a
-
【格芯控台積電】侵16項權利?台積電:其侵權指控並無根據!03月14日
-
【蚊香 悠遊卡】鱷魚牌罐裝蚊香,等比例縮小變3D造型悠遊卡!預購、價格、時間10月04日
-
【iOS 限免】TunesFlow功能超棒的音樂播放器!蘋果限時免費遊戲、應用軟體推薦 (iPhone/iPad) 2017/8/3008月30日
-
【鹿谷推薦】評價最好5家冷氣行!冷氣安裝、維修、價格、保養、灌冷媒、故障、空調、不冷、噪音05月31日
-
【長輩群必備】美玉姨謠言終結者,自動辨識破解LINE假消息、詐騙訊息08月31日
-
【Uber 優步 APP】高檔計程車 叫車 服務及優惠介紹、註冊教學。熱烈下載中!(Android/iPhone iOS/Windows Phone)07月11日
-
【FB訊息停用】臉書APP「Messenger Lite」停止服務!9/18關閉08月25日
-
【健康總篇】治療、美容、保健、舒壓,從頭到腳幫你顧好好!06月24日
-
【免費下載】LINE manga 貼圖「HARIGANE Service」超人氣漫畫!2015/11/1111月11日
-
【2021熱門陸劇】10-12月必看陸劇推薦!下半年、追劇、列表、校園、演員、維基、古裝、情報、時間表、劇情介紹、首播時間!周生如故 | 餘生請多指教 | 驪歌行12月29日
-
【苗栗推薦】評價最好5家磁磚店!施工、種類、價格、免費估價、建材行、磁磚、工程05月01日
-
【屏東推薦】評價最好的5種軌道燈!安裝、種類、價格、優缺點、PTT推薦、缺點、亮度、原理、散光02月19日
-
【寶可夢 0.69.0更新】遙控餵食道館的寶可夢、團體戰獲勝也可以翻轉盤!(Pokemon GO 0.69.0/1.39.0)07月19日
-
【台東推薦】評價最好的5家健身房!課程、教練、價錢、器材、月費01月21日
-
【彰化推薦】門禁系統安裝必知5件事!新安裝、價格、維修、推薦廠商、門禁考勤、讀卡機、電鎖、打卡鐘、打卡機、悠遊卡、上下班、打卡04月18日
-
【IG地點變色】Instagram限動地標怎麼改顏色?打卡功能教學!11月28日