0

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.

1
  • sort($myarr, SORT_NUMERIC); Commented Jun 17, 2014 at 16:01

1 Answer 1

1

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

array_multisort(($sortc), (($sortby==='asc') ? SORT_ASC : SORT_DESC), SORT_NATURAL, $pool);
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.