public function testFlatten() { $object = array(array(1, 2, array(3, array(4, 5)), 6)); $return = array(1, 2, 3, 4, 5, 6); $result = __::flatten($object); $this->assertEquals($return, $result); }
public function testFlatten() { // Arrange $a = [1, 2, [3, [4]]]; $a2 = [1, 2, [3, [[4]]]]; // Act $x = __::flatten($a); $x2 = __::flatten($a2, true); // Assert $this->assertEquals([1, 2, 3, 4], $x); $this->assertEquals([1, 2, 3, [[4]]], $x2); }
public function testFlatten() { $list = array(1, array(2), array(3, array(array(array(4))))); // from js $this->assertEquals(array(1, 2, 3, 4), __::flatten($list), 'can flatten nested arrays'); $this->assertEquals(__::flatten($list, true), array(1, 2, 3, array(array(array(4)))), 'can shallowly flatten nested arrays'); $func = function () { return __::flatten(func_get_args()); }; $result = $func(1, array(2), array(3, array(array(array(4))))); $this->assertEquals(array(1, 2, 3, 4), $result, 'works with arguments'); // docs $list = array(1, array(2), array(3, array(array(4)))); $this->assertEquals(array(1, 2, 3, 4), __::flatten($list)); $this->assertEquals(array(1, 2, 3, array(array(4))), __::flatten($list, true)); }
/** @param $fs [[name => String, path => String]] @param $uId UserId for Edit_Importes table @param $merge Bool true if data should be merged/replaced rather than overwritten @return $log [String] of errors/warnings found by the Importer */ public static function processFiles($fs, $uId, $merge) { array_push(self::$log, "Importer::processFiles for uId {$uId}; merge={$merge}"); $qqs = array(); foreach ($fs as $f) { array_push($qqs, self::mkQueries($f['name'], file_get_contents($f['path']), $merge)); } self::execQueries(__::flatten($qqs), $uId); //Finish, cleaning the log: $log = self::$log; self::$log = array(); return $log; }