What is the Ds\Set sort() function in PHP?
Creating a function in PHP
The following command shows how to create a function,callEducative(), which prints "Welcome to Educative!"
<?phpfunction callEducative() {echo "Welcome to Educative!";}callEducative(); // function call?>
What are data structures?
Data structures are ways of arranging data in computers so that it can be used efficiently. They need to be imported to PHP using the following command:
pecl install ds
What is the Ds\Set sort() function?
This function uses the comparator function to sort the set in place.
Return value
Unlike many other functions, this function does not return a value. By default, ascending order is followed for sorting.
void public Ds\Set::sort([callable $comparator])
Code
The following code illustrates the task performed by the sort() function:
<?php$set = new \Ds\Set([50, 20, 80, 40]);// calling sort$set->sort();print_r($set);?>
Output
[0] => 20
[1] => 40
[2] => 50
[3] => 80