How can I remove json element by sub json value?

Viewed 150

My json like this :

[{"id": 1, "name": "xkCT0QUAK7alZkYkbrLUfxoYyn9aXMh2kyCZeYFW.jpeg"}, 
{"id": 2, "name": "9Tg1QLJGiHPC39KP20iOgy3cYQSXOllJTEBGPcF7.jpeg"}, 
{"id": 3, "name": "fWEfhpRkfy44lqC3Ro1etJKmOOkMXnLJLT4ncS6x.png"}]

I have variable $id

if $id = 2, it will remove json that have id = 2

if $id = 3, it will remove json that have id = 3

For example, it will remove json that have id = 2

The json above to be like this :

[{"id": 1, "name": "xkCT0QUAK7alZkYkbrLUfxoYyn9aXMh2kyCZeYFW.jpeg"}, 
{"id": 2, "name": "fWEfhpRkfy44lqC3Ro1etJKmOOkMXnLJLT4ncS6x.png"}]

When deleted, its id will be sorted back

How can I do it?

1 Answers
Related