Jump to content

Spent hours trying to figure out this array cannot get it


Jason28
Go to solution Solved by 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!

Edited by Jason28
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.