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 1060853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:23:22+00:00 2026-05-16T18:23:22+00:00

i want to sort an array by alphabet when i use asort() its sorting

  • 0

i want to sort an array by alphabet

when i use asort() its sorting , but the results that i get is first of all , the names in upper-case, and after that all the names with lower-case

like :

Avi
Beni
..
..
avi
beni

if i want like :

Avi
avi
Beni
beni
..
..

how can i do it ?

  • 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-05-16T18:23:23+00:00Added an answer on May 16, 2026 at 6:23 pm

    The proposed solutions, until now, arent correct, natcasesort and the usort($arr, ‘strcasecmp’) solutions are failing with some starting array configurations.

    Let do some tests, to find a solution.

    <?php
    $array1 = $array2 = $array3 = $array4 = $array5 = array('IMG1.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG2.png');
    
    // This result is the one we nee to avoid
    sort($array1);
    echo "Standard sorting\n";
    print_r($array1);
    
    // img2.png and IMG2.png are not in the desired order
    // note also the array index order in the result array
    natcasesort($array2);
    echo "\nNatural order sorting (case-insensitive)\n";
    print_r($array2);
    
    // img1.png and IMG1.png are not in the desired order
    usort($array3, 'strcasecmp');
    echo "\nNatural order sorting (usort-strcasecmp)\n";
    print_r($array3);
    
    // Required function using the standard sort algorithm
    function mySort($a,$b) {
      if (strtolower($a)== strtolower($b))
        return strcmp($a,$b);
      return strcasecmp($a,$b);
    }
    
    usort($array4, 'mySort');
    echo "\nStandard order sorting (usort-userdefined)\n";
    print_r($array4);
    
    // Required function using the natural sort algorithm
    function myNatSort($a,$b) {
      if (strtolower($a)== strtolower($b))
        return strnatcmp($a,$b);
      return strnatcasecmp($a,$b);
    }
    
    usort($array5, 'myNatSort');
    echo "\nNatural order sorting (usort-userdefined)\n";
    print_r($array5);
    

    ?>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort an array of strings that contain names and numbers. But
I want to sort the array c. But I don't get the answer a,b,c,d.
I want to sort an array by 'hits', but I also want to look
I have an array that I want to sort based on the value of
I want to sort a flat, associative array by its values alphabetically and preserve
I found out how to sort a JSON array at http://www.devcurry.com/2010/05/sorting-json-array.html Now I want
Hello i do want a sort an array, that contains this: String[] info =
i want to sort an array in such a way that numerals come after
I want to sort an array by strings first and then numbers. How do
I have a 2D-array that I want to sort based on the second column.

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.