PHP Classes

File: doc.txt

Recommend this page to a friend!
  Classes of Przemek Berezowski  >  Array Sorter  >  doc.txt  >  Download  
File: doc.txt
Role: Documentation
Content type: text/plain
Description: Documentation how to use ArraySorter class
Class: Array Sorter
Sort multidimensional arrays
Author: By
Last change:
Date: 11 years ago
Size: 2,008 bytes


Class file image Download
 * ArraySorter
 * Copyright (c) 2011 Przemek Berezowski ( 
 * All rights reserved.

 * @category	  Library
 * @package  	  ArraySorter
 * @copyright     Copyright (c) 2011 Przemek Berezowski (
 * @version       0.9
 * @license       New BSD License

1. Description
	ArraySorter class can be used to sort multidimensional arrays.
	It takes multidimensional array or an array of objects and sorts it 
	by the given value.
	The sorting entry name may include one more entry names, one per each dimension.
	The sorting order may be configured also to be ascending or descending.

2. Preparing ArraySorter to do a job
	First of all create the instance of ArraySorter.
	Secondly set the array to sort using ArraySorter method setArray($array2Sort);
3. Sorting 
	In the class there is public method sort($field, $direction)
	which can be used to sort given array.
	- Sorting by given field
		$field param is a string desribing field position in array.
		Each dimension of array is separated by a dot "."
		Suppose we have such an array
		[0]['name'] = 'something';
		[0]['vandor']['name'] = 'company';
		[0]['vandor']['address']['street'] = 'abbay road';
		[1]['name'] = 'something else';
		[1]['vendor']['name'] = 'company';
		[1]['vendor']['address']['street'] = 'abbay road';
		- to sort by name set param $field to 'name' 
		- to sort by vendor name set param $field to ''
		- to sort by vendor street set param $field to 'vendor.address.street'
		The same naming convention are used to sort array of objects or mixed structures
		where araay can contains objecs which contains array fields.
	- Define sort order
		To define sort order, there are two constants in ArraySorter
		ArraySorter::DIRECTION_ASC - defining ascending sorting direction
		ArraySorter::DIRECTION_DESC - defining descending sorting direction
		These contants can be used as a second parametr for sort method.
4. Any bugs or question please report to
For more information send a message to info at phpclasses dot org.