Welcome Guest, Not a member yet? Register   Sign In
Associative array sorting library based on array's column
#1

[eluser]Ravi Raj[/eluser]
I have introduced codeigniter library for associative array sorting on the basis of array's column. see following lines of code to know How to use library.
Code:
$this->load->library('MY_sort_associative_array');      
    $sorter = new MY_sort_associative_array;
    
    // some starting data
    $start_data = array(
    array('first_name' => 'John', 'last_name' => 'Smith', 'age' => 10),
    array('first_name' => 'Joe', 'last_name' => 'Smith', 'age' => 11),
    array('first_name' => 'Jake', 'last_name' => 'Xample', 'age' => 9),
    );

    // sort by last_name, then first_name
    print_r($sorter->sort_associative_array($start_data, 'last_name', 'first_name'));

    // sort by first_name, then last_name
    print_r($sorter->sort_associative_array($start_data, 'first_name', 'last_name'));

    // sort by last_name, then first_name (backwards)
    $sorter->backwards = true;
    print_r($sorter->sort_associative_array($start_data, 'last_name', 'first_name'));

    // sort numerically by age
    $sorter->numeric = true;
    print_r($sorter->sort_associative_array($start_data, 'age'));

if anybody found any issue then please let me know.


Messages In This Thread
Associative array sorting library based on array's column - by El Forum - 02-17-2010, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB