/** * List files under a path * * @param string $path Path which files will be enlisted * @param boolean $recursive [optional] If listing shall be recursive. Default is FALSE * @return array */ function listfiles($path, $recursive = false) { $iterator = $recursive ? new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS) : new DirectoryIterator($path); $array = \Utils\Arrays::FromTraversable($iterator); if (!$recursive) { $array = \Utils\Arrays::Filter($array, ['.', '..']); } return $array; }
public function testFilter_Recursive() { $test = $this->array; $filter = ['Allen Linatoc', 21, 'Laguna', 14.1241]; $expect = ['address' => ['city' => 'Calamba', 'country' => 'Philippines', 'coordinates' => ['latitude' => 121.00212]]]; $result = Arrays::Filter($test, $filter, true); $this->assertArrayEqual($expect, $result); }