1

I have an array, I just want to remove all empty objects from the array. Here is my array.

{
    "tags": [
        {
            "tags": [
                "php tutorial",
                "php tutorial in hindi"
            ]
        },
        {
            "tags": [
                "php",
                "php tutorial",
                "php tutorial for beginners",
            ]
        },
        {},
        {},
        {
            "tags": [
                "HTML",
                "CSS",
                "JavaScript",
            ]
        },
        {},
        {}
    ]
}
I only want to auto-remove all of empty {} from my tags array. Thanks

1 Answer 1

2

You should first decode the json using json_decode() then use array_filter() method on. It will filter empty values of the array.

array_filter( json_decode($your_array) )
Sign up to request clarification or add additional context in comments.

6 Comments

Here i got an error : json_decode(): Argument #1 ($json) must be of type string, array given
I thought your input is a json. So, if it's an array, just use array_filter( $your_array )
same results even after doing that.
What is the type of your input? String(json) or php array?
So, you can simply use array_filter() method. Read about it here
|

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.