Page 1 of 1

Array Help - Modifying parts of array

Posted: Mon Aug 04, 2008 9:21 am
by Greenconure
I need to store multiple combinations of an ID and a number within an array.
Right now I'm storing them by combining the two strings together with a "-" in the middle and then exploding when I need to access the contents.

My problem lies in that I don't know how to, when the user is adding a new ID/number, check if the ID already exists within the array and modify that entry so that the entry's number value = Old Number + New Number.

Any help?

Also, is there a better way to store the ID/number within an array than how I am currently doing this?

Thanks,
Greenconure

Array "print_r" Example:

Code: Select all

Array
(
    [0] => 1-123
    [1] => 1-100
)

Re: Array Help - Modifying parts of array

Posted: Mon Aug 04, 2008 10:24 am
by Oren
Why not a 2D array?

Re: Array Help - Modifying parts of array

Posted: Mon Aug 04, 2008 10:41 am
by Greenconure
Oren wrote:Why not a 2D array?
That's quite a good point.
I'll most likely end up using an array like the following.
(But there still is the problem of modifying the individual values that I don't know how to do)

Array "print_r" Example:

Code: Select all

Array
(
    [0] => Array
        (
            [0] => Item Number 1
            [1] => Quantity for Item Number 1
        )
 
    [1] => Array
        (
            [0] => Item Number 2
            [1] => Quantity for Item Number 2
        )
 
)

Re: Array Help - Modifying parts of array

Posted: Mon Aug 04, 2008 1:28 pm
by RobertGonzalez
Arrays can be used like little mini database tables. First question I have is why can you not do this with a database? If you can't, then what process are you trying to accomplish with your logic? Not the code process, but the application process. What is your app doing?