public static index ( array | Traversable $Data, string | array $Columns, array $Options = [] ) : array | ||
$Data | array | Traversable | The array to index. It is formatted similar to the array returned by Gdn_DataSet::Result(). |
$Columns | string | array | The name of the column to index on or an array of columns to index on. |
$Options | array | An array of options for the method. - Sep: The string to seperate index columns by. Default '|'. - Unique: Whether or not the results are unique. - true (default): The index is unique. - false: The index is not unique and each indexed row will be an array or arrays. |
리턴 | array |
public static function index($Data, $Columns, $Options = array())
{
$Columns = (array) $Columns;
$Result = array();
$Options = array_change_key_case($Options);
if (is_string($Options)) {
$Options = array('sep' => $Options);
}
$Sep = val('sep', $Options, '|');
$Unique = val('unique', $Options, true);
foreach ($Data as $Row) {
$IndexValues = array();
foreach ($Columns as $Column) {
$IndexValues[] = val($Column, $Row);
}
$Index = implode($Sep, $IndexValues);
if ($Unique) {
$Result[$Index] = $Row;
} else {
$Result[$Index][] = $Row;
}
}
return $Result;
}
/** * Get and store list of current bans. * * @since 2.0.18 * @access public */ public static function &allBans() { if (!self::$_AllBans) { self::$_AllBans = Gdn::sql()->get('Ban')->resultArray(); self::$_AllBans = Gdn_DataSet::index(self::$_AllBans, array('BanID')); } // $AllBans =& self::$_AllBans; return self::$_AllBans; }