0

I have an array in php $arr("ABC","","XYZ","",""). now i want to trim the null values in the array and want $arr("ABC","XYZ"). And the element number must also be manipulated likewise which means "XYZ" must have the key value as 1 after trimming. How do we do it? Thanks in advance! Cheers!

2
  • $result = array_values(array_filter($array)); Commented Aug 15, 2014 at 16:57
  • 1
    Note that those aren't null values that you're removing, they're empty strings Commented Aug 15, 2014 at 16:58

1 Answer 1

6

Use array_filter()

Filters elements of an array using a callback function. If no callback is supplied, all entries of array equal to FALSE (see converting to boolean) will be removed.

$arr = array_filter($arr);
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.