PHP code example of theopeneyes / sort-associative-array

1. Go to this page and download the library: Download theopeneyes/sort-associative-array library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

theopeneyes / sort-associative-array example snippets


$student = array(
	array(
		'name' => array(
			'first_name' => 'Joann',
			'last_name' => 'Daly'
        	),
		'age' => 18, 
		'grade' => 12, 
		'birth_month' => 5
    	),
	array(
		'name' => array(
			'first_name' => 'Jaiden',
			'last_name' => 'Wolf'
		),
		'age' => 15, 
		'grade' => 10, 
		'birth_month' => 8
	),
	array(
		'name' => array(
			'first_name' => 'Lara',
			'last_name' => 'Flores'
		),
		'age' => 8, 
		'grade' => 3, 
		'birth_month' => 2
	)
);

use TheOpenEyes\SortAssociativeArray\SortAssociativeArray;

SortAssociativeArray::column($student, 'age', SORT_DESC);

/* Parameters of 'column' method
    1. Array - The array you would like to sort by.
    2. Column name
    3. Sort Direction - Should be either SORT_ASC or SORT_DESC (Optional, Default is SORT_ASC)
*/

use TheOpenEyes\SortAssociativeArray\SortAssociativeArray;

SortAssociativeArray::columnWithChild($student, 'name', 'first_name', SORT_DESC);

/* Parameters of 'columnWithChild' method
    1. Array - The array you would like to sort by.
    2. Parent column name
    3. Child column name
    4. Sort Direction - Should be either SORT_ASC or SORT_DESC (Optional, Default is SORT_ASC)
*/
 php
"theopeneyes/sort-associative-array": "dev-main",