Is there a way to combine each element of a multidimensional

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Is there a way to combine each element of a multidimensional

Post by phillyrob »

I have a multidimensional array which is a set of exploded numbers .ie

3-4-7
2-5-1
1-2-3
They have been exploded using "-" delimiter to input into a database using a form that I copy and paste the numbers from a spreadsheet. I can load them individually or as a set. just fine. However I need put them into the database combined with another array of letters ie:

Column 1 Column2
A 347
B 251
C 123

The letters array are the name of tables in the database and the numbers are being inserted with each number a different field. Again I can explode and load them fine, but I want to be able to take the letter array, and copy the numbers into the form and have the numbers load into the database based on the names in the letter array. Any ideas would be appreciated.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Is there a way to combine each element of a multidimensi

Post by Celauran »

phillyrob wrote:I have a multidimensional array which is a set of exploded numbers .ie

3-4-7
2-5-1
1-2-3
They have been exploded using "-" delimiter
So you've got $array[0][0] = 3? If so, I'd lose the explode altogether and simply use str_replace to remove the dashes.
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Re: Is there a way to combine each element of a multidimensi

Post by phillyrob »

Thanks Celauran ,

I am not following. Are you saying using str_replace will make it easier to associate each set of numbers that I copy into a form with an array?

the array will have the table names from by db and I will paste around 20 rows of numbers into a form. I just want the each row to be associated with each element of the array when i upload meaning :

Row 1 or (3-2-5) will break up and upload into table A with field names Num1, Num2,Num3

Row 2 or (6-2-7) will break up and upload into table B with field names Num1, Num2,Num3

Row 3 or (4-9-1) will break up and upload into table C with field names Num1, Num2,Num3 and so on?

I still am not sure how to associate each row with each element of the array.
Post Reply