Replaced foreach with array_walk