How to convert a comma-delimited string into array of integers in PHP

1 Answer

0 votes
$string = "1,2,7099,85";

$arr = array_map('intval', explode(',', $string));

print_r($arr);

echo var_dump(is_int($arr[0]));




/*
run:
      
Array
(
    [0] => 1
    [1] => 2
    [2] => 7099
    [3] => 85
)
bool(true)
      
*/

 



answered Aug 5, 2023 by avibootz

Related questions

...