public function testExtraDeepBeginMultipleCyclesAndFollowIndex() { $expected = 1; $cycles = 5; $cur_cycle = 0; $array = [1, 2, 3, 4 => [4, 5, 6 => [6, 7, 8, 9]]]; $index = 0; Each::deep()->begin($array, function ($bag) use(&$expected, &$cur_cycle, &$index, $array) { $actual = $bag->value(); $this->assertEquals($expected, $actual); $expected++; $actual = $bag->cycle(); $this->assertEquals($cur_cycle, $actual); $actual = $bag->index(); $this->assertEquals($index, $actual); $index++; // Here the number six refers to the last item in the // array [1, 2, 3, 4 => [4, 5, 6 => [6, 7, 8, 9]]] if it were flattened. if ($expected > 9) { $expected = 1; $cur_cycle++; } }, $cycles); }