This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/Toolbox/ArrayTools.php
2013-10-02 11:14:53 -05:00

34 lines
679 B
PHP
Executable File

<?php
namespace Rails\Toolbox;
abstract class ArrayTools
{
/**
* Flattens an array.
*/
static public function flatten(array $arr)
{
$flat = array();
foreach ($arr as $v) {
if (is_array($v))
$flat = array_merge($flat, self::flatten($v));
else
$flat[] = $v;
}
return $flat;
}
/**
* Checks if an array is indexed.
*/
static public function isIndexed(array $array)
{
$i = 0;
foreach (array_keys($array) as $k) {
if ($k !== $i)
return false;
$i++;
}
return true;
}
}