vbnullchar Posted April 6, 2009 Share Posted April 6, 2009 I have this array.. <?php $arr = array( array(4,5,6), array(99,23,42), array(112,282,131), array(22,282,131), array(42,1282,1131), array(12,282,131), array(14,2,3), array('b1','b2','b3'), array('a','a2','a3') ); ?> I need to sort the first character of the first value... desired output should be like this... <?php $arr = array( array('a','a2','a3'), array('b1','b2','b3'), array(12,282,131), array(14,2,3), array(112,282,131), array(22,282,131), array(4,5,6), array(42,1282,1131), array(99,23,42) ); ?> meaning arrays with values starts with "1" goes together.. etc.. i tried array_multisort but doesnt solve it because after sorting the order will be 12,13,99,112, the right order is 12,14,112,99 thanks Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 6, 2009 Share Posted April 6, 2009 http://uk2.php.net/manual/en/function.array-multisort.php Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted April 6, 2009 Author Share Posted April 6, 2009 http://uk2.php.net/manual/en/function.array-multisort.php array_multisort will not work, I want to sort the 1st character of the array values Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 6, 2009 Share Posted April 6, 2009 ??? you sure? just use the dort string flag and it should be hunky dory - it may wel put numbers before characters but... Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted April 6, 2009 Author Share Posted April 6, 2009 this is the given array... <?php $arr = array( array(4,5,6), array(99,23,42), array(112,282,131), array(22,282,131), array(42,1282,1131), array(12,282,131), array(14,2,3), array('b1','b2','b3'), array('a','a2','a3') ); ?> it doest matter if letters came first.. my concern is all the values with the same first characters goes together.. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted April 6, 2009 Author Share Posted April 6, 2009 okay I got it... <?php $csv1 = array( array(4,5,6), array(99,23,42), array(112,282,131), array(22,282,131), array(42,1282,1131), array(12,282,131), array(14,2,3), array('b1','b2','b3'), array('a','a2','a3') ); function __unset(&$arr){ unset($arr[0]); } foreach($csv1 as $k => $value){ $v[] = array_merge((array) substr($value[0],0,1), $value ); } array_multisort($v); array_walk($v, "__unset"); print_r($v); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.