0

I have tried many things but none worked, I am sure I am missing something simple.

Here is my array:

$array['Product1'] = 500;
$array['Product2'] = 1230;
$array['Product3'] = 432;
$array['Product4'] = 2000;

Here is the result I want please!

$array['Product4'] = 2000;
$array['Product2'] = 1230;
$array['Product1'] = 500;
$array['Product3'] = 432;

Tried natcasesort, array_reverse, asort, rsort, nothing seems to work. What I am missing here?

Any help is appreciated

1
  • You're missing a description of how those attempted methods failed to work/ Commented Mar 3, 2015 at 22:11

2 Answers 2

2

You tried much, but not the right thing:

arsort($array);

For more information aout arsort() see the manual: http://php.net/manual/en/function.arsort.php

Sign up to request clarification or add additional context in comments.

Comments

0

You probably want arsort: http://php.net/manual/en/function.arsort.php

$array = arsort($array);

There is a comparison of the array sorting types here: http://php.net/manual/en/array.sorting.php

You can also pass sort_flags to arsort - there is a list here: http://php.net/manual/en/function.sort.php (and a link on the arsort link above)

You should end up with:

$array = arsort($array, SORT_NUMERIC);

Comments

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.