Vars being initialized inside a loop is bad for readability. So I would prefer keeping this line and after the foreach loop you can do `$data = empty($data) ? null : $data;`