Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

html
css
web development
php
communitycreator

What is the Ds\Set sort() function in PHP?

Saad Akbar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Creating a function in PHP

The following command shows how to create a function,callEducative(), which prints "Welcome to Educative!"

<?php
function 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   

RELATED TAGS

html
css
web development
php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring