/** * Write an algorithm to add 1 to any integer values in an arbitrary depth * array using php. */ public function testQThree() { require_once __DIR__ . "/../src/data.php"; $clone = $data; incrementIntegerInArray($data); array_walk_recursive($clone, array($this, 'increment')); $this->assertEquals($clone, $data); }
/** * Increment Integer values by 1 * @return void */ function incrementIntegerInArray(&$array) { if (!is_array($array)) { throw new InvalidArgumentException('Invalid Array'); } foreach ($array as $key => &$value) { if (is_array($value)) { incrementIntegerInArray($value); } else { if (is_integer($value)) { $value++; } } } }