Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to use the functionality of SORT_ASC, SORT_DESC with array_multisort()

but the problem is, it sorts my array like

test.1
test.10
test.2
test.3
test.4
test.5

it should be

test.1
test.2
test.3
test.4 
...
test.10

currently using it like this

array_multisort(($sortc), (($sortby==='asc') ? SORT_ASC : SORT_DESC), $pool);

$sortc is the array I want to sort from the multi-dimensional array of $pool

I do know that natsort can do it properly, but it doesnt have the same functionality as array_multisort.

share|improve this question
    
sort($myarr, SORT_NUMERIC); –  Prateek Jun 17 at 16:01

1 Answer 1

up vote 1 down vote accepted

You want to use natural sort. Just add the SORT_NATURAL flag.

array_multisort(($sortc), (($sortby==='asc') ? SORT_ASC : SORT_DESC), SORT_NATURAL, $pool);
share|improve this answer
    
That was worked. thank you! I didn't realize you could add multiple SORT constants to one, I knew you could do many arrays with different sorts. –  Idealcastle Jun 17 at 16:04
    
@Idealcastle Good :) Please mark the answer as accepted. –  Sawny Jun 17 at 16:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.