Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9205781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:02:03+00:00 2026-06-18T00:02:03+00:00

Possible Duplicate: php sort($array) not working – returning 1 instead of sorted array I’m

  • 0

Possible Duplicate:
php sort($array) not working – returning 1 instead of sorted array

I’m having a difficult time getting array sort() function to work as expected, I’ve also tried ksort() etc. :::

This Works Fine

foreach( (array) $query as $post ) {
   $VP = ( ( empty($PMD['vehicle_price'][0]) ) ?  $VP = 'On Request' : $VP = $PMD['vehicle_price'][0] ); 
      $vehicle_p[] = $VP;
}

$return = array_count_values($vehicle_p); //Key Value Unique ( count )

foreach($return as $value => $count) {
   <li><span class="key">' . $value . '</span> (' . $count . ')</li>
}

End Result: 480000 (1), 80000 (2), 120400 (1)

I now want to sort this so 80000 (2) is first in list folowed by 120400 (1) then 480000 (1)

As soon as I add any sort() function like below I only get an output 1

I’m not able to get this to work any help would bew appreciated

$return = array_count_values($vehicle_p); //Key Value Unique ( count )
$return = sort($return);
print_r($return);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:02:04+00:00Added an answer on June 18, 2026 at 12:02 am

    If i understand correctly you want to sort the array by ascending values? if this is correct Look at asort() which will sort the array by value but keep the index/key intact

    http://php.net/manual/en/function.asort.php

    Keep in mind that the sort functions return a Boolean so don’t assign them to a variable, just call the function on the array.

    asort($array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php sort array by sub-value I have a multidimensional array like the
Possible Duplicate: How do I sort a multidimensional array in php I have value
Possible Duplicate: PHP ternary operator not working as expected I dont know what is
Possible Duplicate: Sort array of objects sort an object array in php EDIT: This
Possible Duplicate: How do I sort a multidimensional array in php i need to
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
Possible Duplicate: How do I sort a multidimensional array in php Sorting an associative
Possible Duplicate: How do I sort a multidimensional array in php Array ( [0]
Possible Duplicate: How to sort a date array in PHP I want to sort
Possible Duplicate: How do I sort a multidimensional array in php I have multidimensional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.