You are given an array of strings. You have to sort the given array in standard way (case of alphabets matters) as well as natural way (alphabet case does not matter).

Input : arr[] = {"Geeks", "for", "geeks"} Output : Standard sorting: Geeks for geeks Natural sorting: for Geeks geeks Input : arr[] = {"Code", "at", "geeks", "Practice"} Output : Standard sorting: Code Practice at geeks Natural sorting: at Code geeks Practice

If you are trying to sort the array of string in a simple manner you can simple create a comparison function for character comparison and sort the given array of strings. But that will differentiate lower case and upper case alphabets. To solve this problem if you are otping to solve this in c/java you have to write your own comparison function which specially take care of cases of alphabets. But if we will opt PHP as our language then we can sort it directly with the help of natcasesort().

natcasesort() : It sort strings regardless of their case. Means ‘a’ & ‘A’ are treated smaller than ‘b’ & ‘B’ in this sorting method.

// declare array $arr = array ("Hello", "to", "geeks", "for", "GEEks"); // Standard sort $standard_result = sort($arr); print_r($standart_result); // natural sort $natural_result = natcasesort($arr); print_r($natural_result);

`<?php ` `// PHP program to sort an array ` `// in standard and natural ways. ` ` ` `// function to print array ` `function` `printArray (` `$arr` `) ` `{ ` ` ` `foreach` `(` `$arr` `as` `$value` `) { ` ` ` `echo` `"$value "` `; ` ` ` `} ` `} ` ` ` ` ` `// declare array ` `$arr` `= ` `array` `(` `"Hello"` `, ` `"to"` `, ` `"geeks"` `, ` `"for"` `, ` `"GEEks"` `); ` ` ` `// Standard sort ` `$standard_result` `= ` `$arr` `; ` `sort(` `$standard_result` `); ` `echo` `"Array after Standard sorting: "` `; ` `printArray(` `$standard_result` `); ` ` ` `// natural sort ` `$natural_result` `= ` `$arr` `; ` `natcasesort(` `$natural_result` `); ` `echo` `"\nArray after Natural sorting: "` `; ` `printArray(` `$natural_result` `); ` `?> ` |

*chevron_right*

*filter_none*

Output:

Array after Standard sorting: GEEks Hello for geeks to Array after Natural sorting: for geeks GEEks Hello to

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Insertion sort to sort even and odd positioned elements in different orders
- Sort a linked list that is sorted alternating ascending and descending orders?
- Program to sort an array of strings using Selection Sort
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- PHP program to find the Standard Deviation of an array
- Bead Sort | A Natural Sorting Algorithm
- Sort permutation of N natural numbers using triple cyclic right swaps
- Bucket Sort To Sort an Array with Negative Numbers
- Sort an Array which contain 1 to N values in O(N) using Cycle Sort
- Add elements in start to sort the array | Variation of Stalin Sort
- C Program to Sort an array of names or strings
- Sort an array of strings according to string lengths
- Sort the array of strings according to alphabetical order defined by another string
- Sort an array of strings based on the frequency of good words in them
- Sort an array of strings according to string lengths using Map
- Sort an Array of Strings according to the number of Vowels in them
- Sort an array of Strings according frequency
- Sort an array of strings based on the given order
- Sort the Array of Strings on the basis of given substring range
- Sort an array of strings lexicographically based on prefix

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.