Say I have the string 1,2,3,4,5
and I want to convert this to an array of integers - what would be the best way?
I know I can use explode to create an a
You could also type cast it.
$string = "1,2,3,4,5";
$explode = explode(',', $string);
foreach ($explode as $key)
$arrIntegers[] = (int) $key;
var_dump($arrIntegers);
You can use array_map to apply intval to each array item after you explode the string:
$string = "1,2,3,4,5";
$int_array = array_map("intval", explode(",", $string));