Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i've got this array in PHP

Array(
    'id' => Array(
        'yearid' => '2000', 
        'typeid' => 'something', 
        'value' => 'somevalue'
    )
    'id2' => Array ...
    ...
)

What i'm trying to achive with it is to create a new array of same structure and values in the key 'value', but with different 'yearid' and 'typeid' values. (it is basically a copy of database entry spread across four tables).

I simply want to insert a year which has some id into database with newly generated id and then replace the oldid in array with this newid. All this done in foreach. Then go to 'types' table and do the same thing with that, leaving the value same.

I'am struggling with this for about two hours and i can§t find a solution. (PS: i don't really care about database performance as this will be an seldom used feature. Thats why i am using this approach)

share|improve this question
2  
Can you put together an example of the output you want? –  Matt Jul 29 '13 at 12:15
    
Can you clarify your use of ids. You have a yearid, typeid and the key of the array is 'id'. –  David Normington Jul 29 '13 at 12:18
    
Now that i read it i see that i wasn't much clear. In the Array provied, there is a list of entries corresponding with a database table. id is own id from the table, yearid is a foreign key to table containing years and typeid is a foreign key to another table containing types. –  j0hny Jul 29 '13 at 13:21
    
I came up with a solution using foreach loop every time i want to change a year or type id, and compare is to original. If it matches, replace it with new one. It works but its not a great solution since there will be enormous number of loops... –  j0hny Jul 29 '13 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.