I have this array for example:
$exampleArray = array (
array( 'Name' => 'Opony', 'Kod' =>'OPO', 'Price' => 100 ),
array( 'Kod' =>'OLE', 'Name' => 'Olej', 'Price' => 20 ),
array( 'Kod' =>'ABC', 'Price' => 20, 'Name' => 'abcdefg' )
)
Keys in sub array are in random order. I want to sort the sub arrays by key:
Array ( [0] => Array ( [Kod] => OPO [Name] => Opony [Price] => 100 ) [1] => Array ( [Kod] => OLE [Name] => Olej [Price] => 20 )
I try this:
function compr($x,$y){
if($x == $y)
return 0;
elseif($x>$y)
return 1;
elseif($x<$y)
return-1;
}
uksort($exampleArray, 'compr');
print_r($exampleArray);
But this code doesn't give me my expected result, what is wrong, how can I solve it?