#### 将一个二维数组按照指定字段的值分组
**代码:**
~~~
function groupBy($arr, $key_field) {
$ret = array ();
foreach ( $arr as $row ) {
$key = $row [$key_field];
$ret [$key] [] = $row;
}
return $ret;
}
~~~
**调用:**
~~~
$rows = array(
* array('id' => 1, 'value' => '1-1', 'parent' => 1),
* array('id' => 2, 'value' => '2-1', 'parent' => 1),
* array('id' => 3, 'value' => '3-1', 'parent' => 1),
* array('id' => 4, 'value' => '4-1', 'parent' => 2),
* array('id' => 5, 'value' => '5-1', 'parent' => 2),
* array('id' => 6, 'value' => '6-1', 'parent' => 3),
* );
* $values = Helper_Array::groupBy($rows, 'parent');
*
* dump($values);
* // 按照 parent 分组的输出结果为
* // array(
* // 1 => array(
* // array('id' => 1, 'value' => '1-1', 'parent' => 1),
* // array('id' => 2, 'value' => '2-1', 'parent' => 1),
* // array('id' => 3, 'value' => '3-1', 'parent' => 1),
* // ),
* // 2 => array(
* // array('id' => 4, 'value' => '4-1', 'parent' => 2),
* // array('id' => 5, 'value' => '5-1', 'parent' => 2),
* // ),
* // 3 => array(
* // array('id' => 6, 'value' => '6-1', 'parent' => 3),
* // ),
* // )
~~~