After several hours of Picasso coding (my term), I am stuck on how to efficiently convert this JavaScript array of objects into PHP (sent via AJAX).
In JavaScript, the array of objects looks like this after JSON encoding:
[
{"pid":"282","seller_id":"3","qty":"5"},
{"pid":"284","sn":"1234","seller_id":2,"qty":"1"},
{"pid":"284","sn":"2345","seller_id":2,"qty":"1"},
{"pid":"284","sn":"3456","seller_id":2,"qty":"1"},
{"pid":"111","sn":"987","seller_id":2,"qty":"1"}
]
There are two data groupings - note that the first transfer lacks a serial number and is to an external vendor, making it a sale. The next 4 are all to "myself" (user is seller_id: 2), so these are internal transfers of product.
Anyway, the two types must be handled differently, so it would be immensely helpful if they were in separate arrays.
Therefore, I wish to end up with two PHP arrays:
arrSale[0] = "pid":"282","seller_id":"3","qty":"5"
and
arrXfer[0] = "pid":"284","sn":"1234","seller_id":2,"qty":"1"
arrXfer[1] = "pid":"284","sn":"2345","seller_id":2,"qty":"1"
arrXfer[2] = "pid":"284","sn":"3456","seller_id":2,"qty":"1"
arrXfer[3] = "pid":"111","sn":"987","seller_id":2,"qty":"1"
I know that I must use $arrPHP = json_decode(jsonItems);
to decode the JSON, but what happens to the objects? How would I break them into the two groups? I can't even find website resources that discuss this.
sn
property or not