PHP natcasesort() Function6 Jan 2025 | 2 min read The natcasesort( ) function is used to sort an array using a case insensitive "natural array" algorithm. The function implements a sort algorithm but maintains original keys and values. This function was introduced in PHP 4.0. SyntaxParameter
ReturnsThe natcasesort( ) function returns true on success or false on failure. Example 1Output: Standard sorting Array ( [0] => Rahul [1] => Sachin [2] =>sehwag [3] =>virat ) Natural order case insensitve: Array ( [2] => Rahul [0] => Sachin [1] =>sehwag [3] =>virat ) Example 2Output: Standard sorting Array ( [0] => Code1.php [1] => Code22.txt [2] => code12.php [3] => code2.php [4] => code3.php ) Natural order case insensitve: Array ( [4] => Code1.php [2] => code2.php [3] => code3.php [0] => code12.php [1] => Code22.txt ) Example 3Output: Standard sorting Array ( [0] => IMG0.png [1] => IMG3.png [2] => img1.png [3] => img10.png [4] => img12.png [5] => img2.png ) Natural order case insensitve: Array ( [0] => IMG0.png [4] => img1.png [3] => img2.png [5] => IMG3.png [2] => img10.png [1] => img12.png ) Example 4Output: Standard sorting Array ( [0] => Java [1] => Python [2] => Swift [3] =>php ) Natural order case insensitve: Array ( [0] => Java [1] =>php [3] => Python [2] => Swift ) Next TopicPhp-array-natsort-function |
The array_replace() function is a built-in function in PHP. The PHP array_replace( ) function is used to replace the values of the first array with the values from following arrays. This function was introduced in PHP 5.3.0. Syntax array array_replace ( array $array1 [, array $... ]...
1 min read
PHP array_count_values() Function The array_count_values() function returns an array where the keys are the original array's values, and the values is the number of occurrences. In other words, we can say that array_count_values() function is used to calculate the frequency of all of the elements of...
1 min read
PHP ksort() Function The PHP ksort() sorts an associative array in ascending order, according to the key. It is mainly used for an associative array. This function was introduced in PHP 4.0. Syntax bool ksort ( array &$array [, int $sort_flags = SORT_REGULAR ] ); Parameter Parameter Description Is compulsory array Specifies the array...
1 min read
The in_array( ) function is an inbuilt function of PHP. It is used to search an array for a specific value. If the third parameter strict is set to true, the in_array( ) function will also check the types of the $values. Syntax bool in_array ( mixed...
1 min read
The array_intersect( ) function is used to Computes the intersection of arrays. It compares two or more arrays and returns an array containing all the values of the first array that are present in other arrays. In this operation, keys are preserved. This function was...
1 min read
The array_diff_assoc() function is used to compare an array against another array and returns the difference. In other words, we can say that array_diff_assoc() function compares the keys and values of two or more arrays and return an array that contains the entries from array1...
1 min read
The array_pad() function is a built-in function of PHP. The array_pad() function inserts a specified number of elements, with a specified value, to an array. This function was introduced in PHP 4.0. Syntax array array_pad ( array $array , int $size , mixed $value ); Parameters Parameter Description Required/Optional array Specifies an array. compulsory size Specifies...
1 min read
The array_key_last( ) function is used to get the last key of an array. This function was introduced in PHP 7.3.0 Syntax mixed array_key_last ( array $array ); Parameters Parameter Description Is compulsory array Specifies the array. compulsory Return Values The array_key_last( ) function returns the last key of the array if the array is not...
1 min read
The array_slice() function is an inbuilt function of PHP. The array_slice() function is used to extract a slice of an array. This function was introduced in 4.0. Syntax array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = FALSE ]]...
1 min read
PHP range() Function The PHP range( ) function is used to create an array containing a range of elements. The PHP range( ) function returns an array of elements from low to high. This function was introduced in PHP 4.0. Syntax array range ( mixed $start , mixed...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India