I'm looking for a way to add and remove values from an array based on whether or not the value already exists in said array. I have an orders table set up that contains a select box, customer name and order ID and I'm looking to build this array based on the customer names.
Order Table
-----------
Select Customer Order_ID
------------------------------
[X] Joe 1
[X] Joe 2
[] Mark 3
[] Mark 4
[X] Mark 5
I'm creating a Customer array which pushes the selected customer names in the table. In the case above, if a selected name already exists in the array then just ignore said name, so the array should show....
//this
customerArray["Joe", "Mark"]
//not this
customerArray["Joe", "Joe", "Mark"]
However, it shouldn't remove the customer's name from the array until there are no selected records containing the customers name in said array.
Order Table
-----------
Select Customer Order_ID
------------------------------
[X] Joe 1
[] Joe 2
[] Mark 3
[] Mark 4
[X] Mark 5
This should still have
customerArray["Joe", "Mark"]
However...
Order Table
-----------
Select Customer Order_ID
------------------------------
[] Joe 1
[] Joe 2
[] Mark 3
[] Mark 4
[X] Mark 5
This should be
customerArray["Mark"]
I'm getting confused how to handle the duplicate names and removing them if the said name is no longer selected. Any help would be greatly appreciated.