Hi, I have a couple of questions about arrays, I wondered if anyone could help.
I want to store some data for the duration of a script. The data is a project and its status.
Project ID can be any number, active can be either one of zero.
I’d like to be able to:
Question 1. Store the following information in an array (or better data structure if appropriate). I’d rather not store it in a database until the script finished as in theory the data could update many thousands of times before the script completes and it seems it would put a strain on the database and take longer to run if it had to keep reading and writing the data.
Data is (example only):
Project ID | Active
134 | 1
54 | 1
12 | 1
56 | 1
5476 | 1
There could be a lot more entries (although probably never more than 50). Is an array the best way to store this data, bearing in mind the ‘active’ value needs to stay associated with the relevant project ID?
Question 2. Move an item to a different position in the array. For example I might have:
Project ID | Active
134 | 1
54 | 1
12 | 1
56 | 1
5476 | 1
I’d like to then be able to move the entry with 56 | 1 (for example) to the second entry in the array (or any other position of my choice) so the new order of the array is:
Project ID | Active
134 | 1
56 | 1
54 | 1
12 | 1
5476 | 1
Can this be done with a simple command or would I need to re-create the whole array?
Question 3: When a project is changed from Active 1 to Active 0 I’d like to reorder the array so that the inactive project is moved below all of the active ones, but above any that have previously been marked as inactive. So for example if I have the following array:
Project ID | Active
134 | 1
56 | 1
54 | 1
12 | 1
5476 | 0
And then the entry 56 | 1 is changed to 56 | 0 I’d like the array to become:
Project ID | Active
134 | 1
54 | 1
12 | 1
56 | 0
5476 | 0
Again, can this be done with a simple command or would I need to re-create the whole array?
If there is a better way to do all of the above I’d love to know! If not, can anyone point me towards the necessary commands?
Cheers!