How to convert a comma separated string of numbers to an array of integers in PHP

1 Answer

0 votes
$s = "1,2,3,4";

$arr = array_map("intval", explode(",", $s));

print_r($arr);



/*
run:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) 
 
*/

 



answered Mar 2, 2019 by avibootz
...