0

Simple functions like PHP_SORT doesn't work, also tips from comments couldn't help me enough. I'm trying to sort my table by int values but I can't manage it. This is sample of my table.

array(3) {
 ["normal"]=>
 array(20) {
[58]=>
int(7343)
[33]=>
int(7032)
[34]=>
int(7322)
[65]=>
int(7017)
[60]=>
int(6996)
[62]=>
int(7022)
[35]=>
int(6508)
[56]=>
int(7323)
[61]=>
int(413)
[57]=>
int(7327)
[67]=>
int(7001)
[72]=>
int(6469)
[64]=>
int(5297)
[59]=>
int(5135)
[71]=>
int(5322)
[70]=>
int(5452)
[69]=>
int(6556)
[68]=>
int(6436)
[66]=>
int(6840)
[48]=>
int(6862)
 }
 ["high"]=>
array(19) {
[58]=>
int(2717)
[60]=>
int(2562)
[33]=>
int(2718)
[34]=>
int(2722)
[61]=>
int(1964)
[64]=>
int(2337)
[65]=>
int(368)
[67]=>
int(2308)
[72]=>
int(1880)
[59]=>
int(2202)
[57]=>
int(2587)
[56]=>
int(1474)
[62]=>
int(2416)
[48]=>
int(2455)
[35]=>
int(2356)
[69]=>
int(1910)
[71]=>
int(2229)
[68]=>
int(2293)
[63]=>
int(2582)
 }
  ["low"]=>
 array(12) {
[58]=>
int(1905)
[48]=>
int(1771)
[60]=>
int(1842)
[56]=>
int(1179)
[57]=>
int(1714)
[64]=>
int(1243)
[34]=>
int(1903)
[63]=>
int(57)
[59]=>
int(1837)
[35]=>
int(1725)
[62]=>
int(1594)
[33]=>
int(1858)
 }
}

Please give me some tips. I will be very pleased.

SOLUTION:

$newArray = array();
foreach($morning_code as $k=>$subArray){
   arsort($subArray);
   $newArray[$k] = $subArray;
}
var_dump($newArray);
Kordian Wikliński
  • 55
  • 1
  • 3
  • 11
  • "doesn't work" is a pretty crappy problem description – PeeHaa Feb 18 '14 at 08:57
  • 2
    do you need to maintain index association? – Nouphal.M Feb 18 '14 at 08:59
  • it's very good tip with maintain index association like here http://stackoverflow.com/questions/9898822/sort-array-in-php-by-value-and-maintain-index-association but in my case it sorts by number of results , so after sorting, i got low(12)... high(19)... normal(20) ... where '...' are unsroted results. Anyway this is all i wanted to help me :) Thank You – Kordian Wikliński Feb 18 '14 at 09:06
  • how you want output to be like? – nerkn Feb 18 '14 at 09:09
  • sorted by (int) values in low,normal and high. like ['low']=> [33]=>int(233) [16]=>int(444) [42]=>int(777) // by int values int(value) – Kordian Wikliński Feb 18 '14 at 09:14

2 Answers2

1

if you want to value sort use below

$sortingen = array("normal"=> array(58=>7343,33=>23424,
newArray = Array();

foreach($sortingen as $k=>$subArray){
    sort($subArray);
    newArray[$k] = $subArray;
}

if you want to key sort use below

$sortingen = array("normal"=> array(58=>7343,33=>23424,
newArray = Array();

foreach($sortingen as $k=>$subArray){
    ksort($subArray);
    newArray[$k] = $subArray;
}
nerkn
  • 1,867
  • 1
  • 20
  • 36
0

You can use arsort to sort your array.

<?php arsort(array); ?>

berentrom
  • 505
  • 1
  • 5
  • 12