here is an example of the JSON generated from values retrieved from my database:
{
"product": [
{
"id": "1",
"title": "producta",
"size": "50",
"weight": "1000",
"quantity": "100",
"cartID": "1"
},
{
"id": "2",
"title": "productb",
"size": "50",
"weight": "1000",
"quantity": "100",
"cartID": "2"
},
{
"id": "3",
"title": "productb",
"size": "10",
"weight": "9000",
"quantity": "100",
"cartID": "3"
},
{
"id": "4",
"title": "productd",
"size": "100",
"weight": "500",
"quantity": "100",
"cartID": "4"
},
{
"id": "5",
"title": "producta",
"size": "45",
"weight": "880",
"quantity": "120",
"cartID": "5"
}
]
}
When the user selects to remove an item from the shopping cart, the variable $remove_cartid is passed to my PHP page. If $remove_cartid = 4, then the product with “cartID”: “4” must be removed:
{
"product": [
{
"id": "1",
"title": "producta",
"size": "50",
"weight": "1000",
"quantity": "100",
"cartID": "1"
},
{
"id": "2",
"title": "productb",
"size": "50",
"weight": "1000",
"quantity": "100",
"cartID": "2"
},
{
"id": "3",
"title": "productb",
"size": "10",
"weight": "9000",
"quantity": "100",
"cartID": "3"
},
{
"id": "5",
"title": "producta",
"size": "45",
"weight": "880",
"quantity": "120",
"cartID": "5"
}
]
}
I have made several attempts using the PHP explode function to try and remove the product from the JSON list, but I feel that there is a better way (one that will actually work)
Any advice or help is greatly appreciated
1 Answer