Page 1 of 1

[SOLVED] - Implode 2 arrays into 1

Posted: Sun Sep 02, 2007 10:27 pm
by iknownothing
Hey Guys,

I am Posting 2 arrays, which have to go into the database in one column. What needs to happen is it needs to go in a certain order in the implode, eg.

Code: Select all

Array1[0],Array2[0],Array1[1],Array2[1],Array1[2],Array2[2]
array_merge() is close, but not exactly what I'm looking for.

Does anyone know how this could be done easily?

Posted: Sun Sep 02, 2007 10:29 pm
by s.dot
array_merge() in the order you want... i guess

i'm guessing you don't really need the arrays in that order, just the values? of which case sort() might do you some good.

Posted: Sun Sep 02, 2007 10:44 pm
by iknownothing
no, the array itself HAS to be in that order. Heres an example:

Code: Select all

Size:     Price:
(Array1)  (Array2)
2L        $100.00
1L        $50.00
500mL     $25.00
250mL     $12.50
so the array should be..

Code: Select all

2L,$100.00,1L,$50.00,500mL,$25.00,250mL,$12.50
See, each price value, HAS to stay with its size...

Posted: Sun Sep 02, 2007 11:34 pm
by iknownothing
Solved, probably a bad habit, but this is how I did it...

Code: Select all

$sizea = array_combine($_POST['size'], $_POST['pricea']);
		foreach ($sizea as $key => $value){
		$sizeaa .= $key . "," . $value . ","; 
		}

Posted: Sun Sep 02, 2007 11:37 pm
by s.dot
Why not a nested array?

Code: Select all

$array = array(
   'size1' => 'price 1',
   'size2' => 'price 2'
);
Then you could serialize() the array and store it in your database.