Change language

PHP Ds / Vector sort () function

Syntax:
void public DsVector::sort ($comparator)
Parameters: this function takes one parameter $comparator which is used to store the sorting function.Return value:This function does not return any value. The following programs illustrate the Ds / Vector::sort()function in PHP:Program 1:  
// Declare a new vector $vect = new DsVector ([6, 5, 4, 3, 2, 1]); echo ( " Original vector " );  
// Show vector elements print_r ( $vect );  
// Use the sort() function to sort
// vector elements $vect -> sort(); echo ( " Sorted elements " );  
// Show sorted vector
// elements print_r ( $vect );  
?>
Output:
Original vector DsVector Object ([0] = > 6 [1] = > 5 [2] = > 4 [3] = > 3 [4] = > 2 [5] = > 1) Sorted elements DsVector Object ([0] = > 1 [1] = > 2 [2] = > 3 [3] = > 4 [4] = > 5 [5] = > 6)
Program 2:  
// Declare a new vector $vect = new DsVector ([3, 6, 1, 2, 9, 7]); echo ( " Original vector " );  
// Show vector elements print_r ( $vect );  
// Use the sort() function to sort
// vector elements $vect -> sort ( function ( $element1 , $element2 ) { return $element2 < = > $element1 ; }); echo ( " Decreasing Sorted elements " );  
// Show sorted vector
// elements print_r ( $vect );  
?>
Output:
Original vector DsVector Object ([0] = > 3 [1] = > 6 [2] = > 1 [3] = > 2 [4] = > 9 [5] = > 7) Decreasing Sorted elements DsVector Object ([0] = > 9 [1] = > 7 [2] = > 6 [3] = > 3 [4] = > 2 [5] = > 1 )
Link: http://php.net/manual /en/ds-vector.sort.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