moved array_push in foreach loop