surion Posted December 4, 2007 Share Posted December 4, 2007 hi, i got an array containing arrays, wich should get sorted one way or another. this is what the array looks like (var_dump of it) array(234) { [0]=> array(1) { [746]=> string(15) "X some alphanumeric data" } [1]=> array(1) { [747]=> string(15) "F some alphanumeric data" } [2]=> array(1) { [748]=> string(17) "E some alphanumeric data" } [3]=> array(1) { [749]=> string(11) "ER some alphanumeric data" } [4]=> array(1) { [750]=> string(10) "some alphanumeric data" } [5]=> array(1) { [751]=> string(22) "lsqmdkd some alphanumeric data" } } the big array should have the "smaller arrays" in alphabetical order of the string values inside the smaller arrays, is there a possibility to fix this easy? by the way, it is of great importance that the key and the string of the smaller arrays stay together i can't sort the data before it goes into the array, because i don't put it in there myself. i just get the array as it is *edit* dunno if i explained good enough, but this is what it should look like after the sorting: array(234) { [0]=> array(1) { [748]=> string(17) "E some alphanumeric data" } [1]=> array(1) { [749]=> string(11) "ER some alphanumeric data" } [2]=> array(1) { [747]=> string(15) "F some alphanumeric data" } [3]=> array(1) { [751]=> string(22) "lsqmdkd some alphanumeric data" } [4]=> array(1) { [750]=> string(10) "some alphanumeric data" } [5]=> array(1) { [746]=> string(15) "X some alphanumeric data" } } Link to comment https://forums.phpfreaks.com/topic/80120-solved-advanced-array-sorting/ Share on other sites More sharing options...
sasa Posted December 4, 2007 Share Posted December 4, 2007 try[code[<?php function my_comp($a, $b){ foreach ($a as $v) $x = strtolower($v); foreach ($b as $v) $y = strtolower($v); if ($x > $y) return 1; if ($x == $y) return 0; return -1; } $a = array(array(746=>"X some alphanumeric data"), array(747=>"F some alphanumeric data"), array(748=>"E some alphanumeric data"), array(749=>"ER some alphanumeric data"), array(750=>"some alphanumeric data"), array(751=>"lsqmdkd some alphanumeric data") ); usort($a, 'my_comp'); print_r($a); ?> Link to comment https://forums.phpfreaks.com/topic/80120-solved-advanced-array-sorting/#findComment-406027 Share on other sites More sharing options...
surion Posted January 9, 2008 Author Share Posted January 9, 2008 a bit late reply (been on some other programming for a while): i don't realy understand the code you gave, but it seems to work perfect, so ehm, thx alot !! Link to comment https://forums.phpfreaks.com/topic/80120-solved-advanced-array-sorting/#findComment-434547 Share on other sites More sharing options...
thomashw Posted January 9, 2008 Share Posted January 9, 2008 Make sure you mark the topic solved! Link to comment https://forums.phpfreaks.com/topic/80120-solved-advanced-array-sorting/#findComment-434550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.