I have an variable like ****
I want to explode it.
I am using
$myVal= "C,6,11";
$garray = array_map('intval', explode(',', $myVal));
but i get 0,6,11
i want C in-place of 0. how it possible?
I have an variable like ****
I want to explode it.
I am using
$myVal= "C,6,11";
$garray = array_map('intval', explode(',', $myVal));
but i get 0,6,11
i want C in-place of 0. how it possible?
If you need the numbers to have an integer type in the resulting array you could try something like this:
$myVal= "C,6,11";
$garray = array_map(function($value) {
if(strval($value) === strval(intval($value))) {
return intval($value);
} else {
return $value;
}
}, explode(',', $myVal));
however, if you don't care about the type you can just do that:
$myVal= "C,6,11";
$garray = explode(',', $myVal);