lundi 29 juin 2015

post multideminsional array in multideminsional array


We need to post products here.

The product will have more than one color, while each color have different image.

I have created a form. in this form when user click add more color, it will create them a block div to pick up multiple images for that color, and so on for the next color.

Here is the sketch or input that I will create dynamically with js

<input type="text" name="color[red]" value="red" /> 
    <input name="color[red][image1]" /> 
    <input name="color[red][image2]" /> 
    <input name="color[red][image3]" /> 
    <input name="color[red][image4]" /> 

<input type="text" name="color[blue]" value="blue" />
    <input name="color[blue][image1]" /> 
    <input name="color[blue][image2]" /> 
    <input name="color[blue][image3]" /> 
    <input name="color[blue][image4]" /> 


    And so on...

I need a help how to post the inputs above with php, so that the output array would be like this:

array
    (
        [0] => array
                (
                    name => one
                    id => 1
                    color => array
                                (
                                    [0] => array 
                                                (
                                                    name =>red
                                                    image => array 
                                                                (
                                                                    [0] =>oneRed1.jpg
                                                                    [1] =>oneRed2.jpg
                                                                    [2] =>oneRed3.jpg
                                                                )   
                                                )   
                                    [1] => array 
                                                (
                                                    name =>blue
                                                    image => array 
                                                                (
                                                                    [0] =>oneBlue1.jpg
                                                                    [1] =>oneBlue2.jpg
                                                                    [2] =>oneBlue3.jpg
                                                                )   
                                                )   
                                    [2] => array 
                                                (
                                                    name =>purple
                                                    image => array 
                                                                (
                                                                    [0] =>onePurple1.jpg
                                                                    [1] =>onePurple2.jpg
                                                                    [2] =>onePurple3.jpg
                                                                )   
                                                )   
                                )
                )
        [1] => array
                (
                    name => two
                    id => 2
                    color => array
                                (
                                    [0] => array 
                                                (
                                                    name =>red
                                                    image => array 
                                                                (
                                                                    [0] =>twoRed1.jpg
                                                                    [1] =>twoRed2.jpg
                                                                    [2] =>twoRed3.jpg
                                                                )   
                                                )   
                                    [1] => array 
                                                (
                                                    name =>blue
                                                    image => array 
                                                                (
                                                                    [0] =>twoBlue1.jpg
                                                                    [1] =>twoBlue2.jpg
                                                                    [2] =>twoBlue3.jpg
                                                                )   
                                                )   
                                    [2] => array 
                                                (
                                                    name =>purple
                                                    image => array 
                                                                (
                                                                    [0] =>twoPurple1.jpg
                                                                    [1] =>twoPurple2.jpg
                                                                    [2] =>twoPurple3.jpg
                                                                )   
                                                )   
                                )
                )
    )

Thank you very much in advance for any help.


Aucun commentaire:

Enregistrer un commentaire