Jump to content

uksort() help


asmith

Recommended Posts

Hello.

 

I have an array like this and trying to sort it by its keys:

<?php

$as = array(4 => 'a', 1 => 'd', 'A' => 'f', 10 => 'g');

function natSortMe($a, $b)
{
if ($b == 'A')
	return -1;
if ($a == $b)
	return 0;
else
	return $a > $b? -1 : 1;
}

uksort($as, 'natSortMe');
print_r($as);
?>

 

I want the letter key comes first, then number from highest to lowest. the code above returns this:

Array

(

    [10] => g

    [4] => a

    [1] => d

    [A] => f

)

 

any idea?

Link to comment
https://forums.phpfreaks.com/topic/187563-uksort-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.