mirror of
https://github.com/xivapi/ffxiv-datamining.git
synced 2026-07-24 19:09:10 +00:00
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Libra Database Traits
|
|
* bunch of functions for libra
|
|
*
|
|
* @version 1.0
|
|
* @author Josh Freeman <josh@viion.co.uk>
|
|
*/
|
|
|
|
trait LibraDatabaseTraits
|
|
{
|
|
/**
|
|
* Sorts an array by a column within the array,
|
|
* main use is databases results
|
|
*
|
|
* @param $data - the data to resort
|
|
* @param $column - the column to use for sorting
|
|
* @return Array - the new array!
|
|
*/
|
|
protected function sortDataByColumn($data, $column)
|
|
{
|
|
$newData = [];
|
|
foreach($data as $k => $v)
|
|
{
|
|
$newKey = $v[$column];
|
|
$newData[$newKey] = $this->removeNumericIndexes($v);
|
|
}
|
|
|
|
ksort($newData);
|
|
return $newData;
|
|
}
|
|
|
|
/**
|
|
* Removes numeric indexes, for some reason sqlite
|
|
* returns both table column names and an index list,
|
|
* so this helps strip index's and reduce data duplication
|
|
*
|
|
* @param $data - the array to remove from
|
|
* @return Array - the new array, without numeric indexes!
|
|
*/
|
|
protected function removeNumericIndexes($data)
|
|
{
|
|
foreach($data as $k => $v)
|
|
if (is_numeric($k))
|
|
unset($data[$k]);
|
|
|
|
return $data;
|
|
}
|
|
} |