I'm currently developing an API using Laravel for my project, the concept:
- Retrieve JSON data from MySQL.
- Receive user input from the Front-end (string).
- Convert both JSON and string input into an array with similar structure. The array structure here is basically
["ObjectA", "ObjectA_quantity", "ObjectB", "ObjectB_quantity", ...]
. - Basically, eliminate the quantity of every object of Database's Array, based on every object that User Input's Array got. For example, if the Database's Array got
["pizza", "1", "burger", "2"]
, and the User Input's Array got["pizza", "1"]
, the output of the method is expected to be["burger", "2"]
.
The method that I developed will give inconsistent and confusing output, like for some object, it works well, for other it doesn't eliminate anything and if the User Input's Array too big (> 1 object), it also doesn't eliminate anything. I really welcome different approach or anything else that will give the expected output as above. Thank you very much
Here's the source code of the method I've develop: (method's located on: else if ($transactionGetter->type == 'return')
, Line 148 and so forth)