I'm collecting all form fields on a page via jQuery and then passing them over to a php page in an ajax post, that array is passed like below (actual data is over 60 fields / arrays at present)
Array
(
[0] => Array
(
[0] => main
[1] => text
[2] => product-name
[3] => fieldvalue
)
[1] => Array
(
[0] => main
[1] => select
[2] => product-range
[3] => fieldvalue
)
[2] => Array
(
[0] => main
[1] => select
[2] => product-year
[3] => fieldvalue
)
[3] => Array
(
[0] => main
[1] => text
[2] => product-type
[3] => fieldvalue
)
[4] => Array
(
[0] => main
[1] => text
[2] => product-sku
[3] => fieldvalue
)
[5] => Array
(
[0] => main
[1] => text
[2] => component-name
[3] => fieldvalue
)
[6] => Array
(
[0] => main
[1] => text
[2] => component-stid
[3] => fieldvalue
)
On the form the user can dynamically add multiple sets of the component fields, what I am looking to do is to get group the 7 component fields into an array and then add into a multidimensional array of components that i can sort through later. the way I am currently looping through the array data is as follows
foreach($formdata as $value) {
if($value[0] == 'main') {
if($value[2] == 'product-name') { $productname = $value[3]; }
if($value[2] == 'product-range') { $productrange = $value[3]; }
if($value[2] == 'product-year') { $productyear = $value[3]; }
}
}
I am really struggling to find a clean way of pulling this off, could anyone advise on best practice?
Thanks