ArrayObject natsort() Function in PHP Last Updated : 22 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The natsort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject following a natural order sorting algorithm. The natsort() function is used to sort alphanumeric strings in a order a normal human being would do. Syntax: void natsort() Parameters: This function does not accepts any parameters. Return Value: This function does not returns any value. Below programs illustrate the above function: Program 1: php <?php // PHP program to illustrate the // natsort() function $arr = array("geeks100", "geeks99", "geeks1", "geeks02"); // Create array object $arrObject = new ArrayObject($arr); // Sort the ArrayObject $arrObject->natsort(); // Print the sorted ArrayObject print_r($arrObject); ?> Output: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [3] => geeks02 [2] => geeks1 [1] => geeks99 [0] => geeks100 ) ) Program 2: php <?php // PHP program to illustrate the // natsort() function $arr = array("geeks100", "geeks99", "geeks1", "geeks02"); // Create array object $arrObject = new ArrayObject($arr); // Clone the ArrayObject $tempArrObj = clone $arrObject; // Sort the $temoArrObj using standard // sorting algorithm $tempArrObj->asort(); // Sort the ArrayObject using Natural // ordering algorithm $arrObject->natsort(); // Compare Both of the results echo "Sorted using standard sorting:\n"; print_r($tempArrObj); echo "\nSorted using Natural ordering:\n"; print_r($arrObject); ?> Output: Sorted using standard sorting: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [3] => geeks02 [2] => geeks1 [0] => geeks100 [1] => geeks99 ) ) Sorted using Natural ordering: ArrayObject Object ( [storage:ArrayObject:private] => Array ( [3] => geeks02 [2] => geeks1 [1] => geeks99 [0] => geeks100 ) ) Reference: http://php.net/manual/en/arrayobject.natsort.php Comment More infoAdvertise with us Next Article ArrayObject natsort() Function in PHP gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-array PHP-function PHP-ArrayObject +1 More Similar Reads ArrayObject natcasesort() Function in PHP The natcasesort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject following a natural order case sensitive sorting algorithm. Natural ordering means to arrange the elements in a order a normal human being would do. Syntax: void natcasesort() Parameters: This 2 min read ArrayObject ksort() Function in PHP The ksort() function of the ArrayObject class in PHP is used to sort the elements of the ArrayObject according to the keys. This function does not affects the association of the keys with the values, it just sorts the entries of the ArrayObject according to the Keys. Syntax: void ksort() Parameters: 2 min read ArrayObject uasort() Function in PHP The uasort() function of the ArrayObject class in PHP is used to sort values of an ArrayObject according to a user defined comparison function. The function compares and arranges the values present in the ArrayObject according to the given comparison function. This method does not affects the key-va 2 min read ArrayObject offsetGet() Function in PHP The offsetGet() function of the ArrayObject class in PHP is used to get the value present at a specific index at the ArrayObject. Syntax: mixed offsetGet($index) Parameters: This function accepts a single parameter $index for which corresponding value will be returned. Return Value: This function re 1 min read ArrayObject offsetExists() Function in PHP The offsetExists() function of the ArrayObject class in PHP is used to whether a given offset or index is present in the ArrayObject or not. If it is present then the function returns a boolean True value otherwise it returns False. Syntax: bool offsetExists($index) Parameters: This function accepts 2 min read Like