Jump to content

Spent hours trying to figure out this array cannot get it


Jason28

Recommended Posts

Hello, I cannot figure this out...  I will leave out most of the code to not confuse you, but I have it almost working so I am just missing something.  I have two arrays, one that contains the IDS that I want correctly.  Here is the first array when I print it out:

Array ( [0] => 3 [1] => 9 [2] => 11 )

Perfect, it displays the IDS 3, 9, and 11 like it should.  Now here is my second array when printed out:

Array ( [0] => name value [1] => maker value [2] => year value )

That works too.  name value, maker value, and year value are the results.  I tried using an array_merge on those two arrays hoping that it will turn it into

3 => 'name value',
9 => 'maker value',
11 => 'year value'

For some reason the result I get when I merge these two arrays is:

Array ( [0] => 3 [1] => 9 [2] => 11 [3] => name value [4] => maker value [5] => year value )

It does merge them, but as separate array values.  So when I use my foreach() to insert the values into a DB, I get this as a result:

INSERT INTO fields_table (field_id, field_value) VALUES ('0', '3')
INSERT INTO fields_table (field_id, field_value) VALUES ('1', '9')
INSERT INTO fields_table (field_id, field_value) VALUES ('2', '11')
INSERT INTO fields_table (field_id, field_value) VALUES ('3', 'name value')
INSERT INTO fields_table (field_id, field_value) VALUES ('4', 'maker value')
INSERT INTO fields_table (field_id, field_value) VALUES ('5', 'year value')

What do I do to make the first values equal the second values please?  Thanks.

 

EDIT

 

HAHA I finally figured this out when creating this topic!  I have to use array_combine() instead of array_merge it works perfect now :D  Nevermind I solved it!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.