php usort() with order of precedence for json sorting -
i need sort json array key value pair in order of precedence(specialcharacters > numbers > lower case > uppercase). tried ascii code couldn't expected.
$arr1 = array ( 0 => array ( 'id' => 1, 'name' => 'b', 'value' => 'abc', 'order' => 6, ), 1 => array ( 'id' => 2, 'name' => 'a', 'value' => 'xyz', 'order' => 2, ), 2 => array ( 'id' => 3, 'name' => 'a', 'value' => 'ghi', 'order' => 1, ), 3 => array ( 'id' => 4, 'name' => '123', 'value' => 'xyz', 'order' => 2, ), 4 => array ( 'id' => 5, 'name' => 'd', 'value' => 'uvw', 'order' => 3, ), 5 => array ( 'id' => 6, 'name' => '@2', 'value' => 'def', 'order' => 3, ), ); function cmp($a, $b) { $at = iconv('utf-8', 'ascii//translit', $a['name']); $bt = iconv('utf-8', 'ascii//translit', $b['name']); return strcmp($at, $bt); } usort($arr1, "cmp"); print_r($arr1); can me resolve it?
<?php // obtain list of columns foreach ($arr1 $key => $row) { $arr1[$key] = $row['value']; } ksort($arr1); ?>
Comments
Post a Comment