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/Rails/Toolbox/ArrayTools.php

34 lines
679 B
PHP
Raw Normal View History

2013-10-02 08:12:58 +02:00
<?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;
}
}