如何检查explode只包含逗号分隔值...? [重复]

This question already has an answer here:

How to check that php explode hold only comma separated integer values.

for example i have a

$str= '10,20,30,40,50,60,70,80,90,100';
$arr = explode(',',$str);

and i want to check if the value in $str is 10,20,30 and so on. and cannot contain any of string and words.

I basically populate a drop-down from this $arr and i want to make check if user enter integer values with comma then its show the dropdown else if user enter any other format.

i also use is_int or is_numeric but it cannot solve my problem.

thanks for advance .

</div>

What you're looking for is ctype_digit

$str= '10,20,30,40,50,60,70,80,90,100';
$arr = explode(',',$str);
foreach($arr as $a){
  if(!ctype_digit($a)){
    //Not an int
  }else{
    //is an int
  }
}

Output:- https://eval.in/734431

Reference:- http://php.net/ctype_digit