src/Core/Base.php
public function arrayOrderBy($data, $orderby) {
		// all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3
		$asc = SORT_ASC; 
		$desc = SORT_DESC;
		
		// the array we pass to array_multisort at the end
		$params = [];

		// explode the orderby to use it for array_multisort
		$orderbys = explode(',', $orderby);
		$orderbys = array_map('trim', $orderbys);
		foreach ($orderbys as &$orderby) {
			$parts = explode(" ", $orderby);
			if (!isset($parts[1])) $parts[1] = 'asc';
			$parts[1] = strtolower($parts[1]);
			if (!in_array($parts[1], ['asc', 'desc'])) $parts[1] = 'asc';
			
			// add field name
			$params[] = $parts[0];

			// add sort flag
			if ($parts[1] == 'asc') $params[] =& $asc;
			else $params[] =& $desc;
		}

		// create temp arrays for multisort
		$temp = [];
		$count = count($params)-1;
		for ($i=0; $i<=$count; $i=$i+2) {
			$field = $params[$i];
			$params[$i] = [];
			foreach ($data as $ii => $row) {
				$temp[$field][] = strtolower($row[$field]);
			}
			
			$params[$i] =& $temp[$field];
		}
		
		//now sort
		$params[] =& $data;
		call_user_func_array('array_multisort', $params);
		return $data;
	}
public function arrayOrderBy($data, $orderby) {
		// all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3
		$asc = SORT_ASC; 
		$desc = SORT_DESC;
		
		// the array we pass to array_multisort at the end
		$params = [];

		// explode the orderby to use it for array_multisort
		$orderbys = explode(',', $orderby);
		$orderbys = array_map('trim', $orderbys);
		foreach ($orderbys as &$orderby) {
			$parts = explode(" ", $orderby);
			if (!isset($parts[1])) $parts[1] = 'asc';
			$parts[1] = strtolower($parts[1]);
			if (!in_array($parts[1], ['asc', 'desc'])) $parts[1] = 'asc';
			
			// add field name
			$params[] = $parts[0];

			// add sort flag
			if ($parts[1] == 'asc') $params[] =& $asc;
			else $params[] =& $desc;
		}

		// create temp arrays for multisort
		$temp = [];
		$count = count($params)-1;
		for ($i=0; $i<=$count; $i=$i+2) {
			$field = $params[$i];
			$params[$i] = [];
			foreach ($data as $ii => $row) {
				$temp[$field][] = strtolower($row[$field]);
			}
			
			$params[$i] =& $temp[$field];
		}
		
		//now sort
		$params[] =& $data;
		call_user_func_array('array_multisort', $params);
		return $data;
	}
public function arrayOrderBy ( $ data , $ orderby ) { // all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3 $ asc = SORT_ASC ; $ desc = SORT_DESC ; // the array we pass to array_multisort at the end $ params = [ ] ; // explode the orderby to use it for array_multisort $ orderbys = explode ( ',' , $ orderby ) ; $ orderbys = array_map ( 'trim' , $ orderbys ) ; foreach ( $ orderbys as & $ orderby ) { $ parts = explode ( " " , $ orderby ) ; if ( ! isset ( $ parts [ 1 ] ) ) $ parts [ 1 ] = 'asc' ; $ parts [ 1 ] = strtolower ( $ parts [ 1 ] ) ; if ( ! in_array ( $ parts [ 1 ] , [ 'asc' , 'desc' ] ) ) $ parts [ 1 ] = 'asc' ; // add field name $ params [ ] = $ parts [ 0 ] ; // add sort flag if ( $ parts [ 1 ] == 'asc' ) $ params [ ] = & $ asc ; else $ params [ ] = & $ desc ; } // create temp arrays for multisort $ temp = [ ] ; $ count = count ( $ params ) - 1 ; for ( $ i = 0 ; $ i <= $ count ; $ i = $ i + 2 ) { $ field = $ params [ $ i ] ; $ params [ $ i ] = [ ] ; foreach ( $ data as $ ii => $ row ) { $ temp [ $ field ] [ ] = strtolower ( $ row [ $ field ] ) ; } $ params [ $ i ] = & $ temp [ $ field ] ; } //now sort $ params [ ] = & $ data ; call_user_func_array ( 'array_multisort' , $ params ) ; return $ data ; }
Orders an array like in a SQL query.

Usage example:

~~~{.php}
class Dummy extends \Morrow\Core\Base {
public function sort() {
$data = [
0 => [
'title' => 'Foo',
'position' => 1,
],
1 => [
'title' => 'Bar',
'position' => 0,
],
];

return $this->arrayOrderBy($data, 'position ASC, title ASC');
}
}
~~~

@param  array $data The multidimensional array that should get sorted.
@param  string $orderby An SQL like string to define the ordering.
@return array Returns the sorted array.
Orders an array like in a SQL query .