Replaced a foreach loop with an implode and array_slice