That code should be fine for that too. If you have an organised string where the values are all separated with a common delimiter (in this case a comma) then the
explode() function can split that up for you.
If your string may contain things other than numbers, it might be worth running an
is_numeric() check on each part for validation.
Revised (and still untested) code