PHP natsort() Function6 Jan 2025 | 2 min read The PHP natsort( ) function is used to sort an array using a "natural order" algorithm. The natsort( ) function implements a sort algorithm but maintains original keys and values. This function was introduced in PHP 4.0. SyntaxParameter
ReturnsThe natsort( ) function returns true on success or false on failure. Example 1Output: Standard sorting: Array ( [0] => Ruby [1] => html [2] => java 8 [3] =>php 5 [4] => python ) Natural order: Array ( [0] => Ruby [1] => html [2] => java 8 [3] =>php 5 [4] => python ) Example 2Output: Standard sorting Array ( [0] => code1.php [1] => code12.php [2] => code2.php [3] => code22.php [4] => code3.php ) Natural order sorting Array ( [4] => code1.php [2] => code2.php [3] => code3.php [0] => code12.php [1] => code22.php ) Example 3Output: Standard sorting Array ( [0] => android7 [1] => java8 [2] => php5 [3] => python3 [4] => ruby2 ) Natural order sorting Array ( [4] => android7 [0] => java8 [1] => php5 [2] => python3 [3] => ruby2 ) Example 4Output: Standard sorting Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) Natural order sorting Array ( [3] => img1.png [2] => img2.png [1] => img10.png [0] => img12.png ) Next TopicPhp-array-next-function |
PHP () Function The PHP ( ) function is used to advance the internal array pointer. It advances the internal array pointer one place forward before returning the element value. This function was introduced in PHP 4.0. Syntax mixed ( array &$array ); Parameter Parameter Description Is compulsory array Specifies the array to...
1 min read
The array_key_first( ) function is used to get the first key of an array. This function was introduced in PHP 7.3.0 Syntax mixed array_key_first ( array $array ); Parameters Parameter Description Is compulsory array Specifies the array. compulsory Return Values The array_key_first( ) function returns the first key of the array if the array is not...
1 min read
PHP uasort() Function The PHP uasort( ) function is used to sort an array by its values using a user-defined comparison function. This function was introduced in PHP 4.0. Syntax bool uasort ( array &$array , callable $value_compare_func ); Parameter Parameter Description Is compulsory array Specifies the array to be sorted. compulsory user_defined_function This function is a...
2 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
PHP () Function The PHP ( ) function is used to fetch the array value in the ious place, pointed by the internal array pointer. This function was introduced in PHP 4.0. Syntax mixed ( array &$array ); Parameter Parameter Description Is compulsory array Specifies the array to use. compulsory Returns The ( ) function returns...
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
PHP array diff_ukey() Function The array_diff_ukey() is an inbuilt function in PHP. The array_diff_ukey() function compares the keys of two or more arrays with a user-defined function, and returns an array that contains the entries from array1 that are not present in array2 or array3, etc. This...
2 min read
PHP asort() Function The asort( ) function is an inbuilt function of PHP. The asort( ) function is used to sort an associative array in ascending order, according to the value. This function was introduced in PHP 4.0. Syntax bool asort ( array &$array [, int $sort_flags =...
1 min read
The array_replace_recursive() function is an inbuilt function of PHP. The array_replace_recursive( ) function is used to replace the values from passed arrays into the first array recursively. This function was introduced in PHP 5.3.0. Syntax array array_replace_recursive ( array $array1 [, array $... ] ); Parameter Parameter Description Is compulsory array1 Specifies an...
2 min read
PHP pos() Function The PHP pos( ) function is used to fetch the value of the current element in an array. The PHP pos( ) function is an alias of current( ) function. This function was introduced in PHP 4.0. Syntax pos($array); Parameter Parameter Description Is compulsory array Specifies the array to use. compulsory Returns The pos(...
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