0

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?

1
  • 4
    intval — Get the integer value of a variable. Commented Dec 31, 2020 at 9:46

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.