Change language

PHP Ds / Set sorted () function

Syntax:
DsSet public DsSet::sorted ([callable $comparator])
Parameters :This function takes a comparator function according to which the values ​​are compared when sorting the set. The comparator should return the following values ​​based on a comparison of the two values ​​passed to it as a parameter:
  • 1:if the first element is expected to be less than the second element.
  • -1:if the first element is expected to be larger than the second element.
  • 0:if the first is expected the element will be equal to the second element.
Returned value:Returns a sorted copy of the given set.The programs below illustrate the Ds / Set function::sorted()in PHP:Program 1:
// PHP program to illustrate the sorted() function $set = new DsSet ([20, 10, 30]);  
// sort the set print_r ( $set -> sorted());  
?>
Exit:
DsSet Object ( [0] = > 10 [1] = > 20 [2] = > 30)
Program 2:  
// Declare new set $set = new DsSet ([2, 3, 6, 5, 7, 1, 4]); $sorted = $set -> sorted ( function ( $a , $b ) { return $b < = > $a ; }); print_r ( $sorted );  
?>
Exit:
DsSet Object ( [0] = > 7 [1] = > 6 [2] = > 5 [3] = > 4 [4] = > 3 [5] = > 2 [6] = > 1)
Link: https://www.php. net / manual / en / ds-set.sorted.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method