Change language

PHP Ds / Vector sorted () function

Syntax:
DsVector public DsVector::sorted ($comparator)
Parameters: This function takes one parameter $comparator, which contains the sort function.Return value:This function returns a copy of the sorted vector.The programs below illustrate the Ds / Vector::sorted()function in PHP:Program 1:

 
// Declare a new vector $vect = new DsVector ([6, 5, 4, 3, 2, 1]); echo ( " Original vector " );  
// Show vector elements var_dump ( $vect );  
// Use the sorted() function to sort
// copy of vector elements $res = $vect -> sorted(); echo ( " Sorted elements " );  
// Show sorted items var_dump ( $res );  
?>
Output:
Original vector object (DsVector) # 1 (6) {[0] = > int (6) [1] = > int (5) [2] = > int (4) [3] = > int (3) [4] = > int (2) [5] = > int (1)} Sorted elements object (DsVector) # 2 (6) {[0] = > int (1) [1] = > int (2) [2] = > int (3) [3] = > int (4) [4] = > int (5) [5] = > int (6)}
Program 2:  
// Declare a new vector $vect = new DsVector ([3, 6 , 1, 2, 9, 7]); echo ( " Original vector " );  
// Show vector elements var_dump ( $vect );  
// Use the sorted() function to sort
// copy of vector elements $res = $arr -> sorted ( function ( $element1 , $element2 ) { return $element1 < = > $element2 ; }); echo ( " Sorted elements " );  
// Show sorted items var_dump ( $res );  
?>
Output:
Original vector object (DsVector) # 1 (6) {[0] = > int (3) [1] = > int (6) [2] = > int (1) [3] = > int (2) [4] = > int (9) [5] = > int (7)} Sorted elements object (DsVector) # 3 (6) {[0] = > int (1) [1] = > int (2) [2] = > int (3) [3] = > int (6) [4] = > int (7) [5] = > int (9)}
Link: http: // php .net / manual / en / ds-vector.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