In php, I need to turn this array:
array(
'group1_selector1_rule1' => value
, 'group1_selector1_rule2' => value
, 'group1_selector1_rule3' => value
, 'group1_selector2_rule1' => value
, 'group1_selector2_rule2' => value
, 'group2_selector1_rule1' => value
, 'group2_selector1_rule2' => value
, 'group3_selector1_rule1' => value
, 'group3_selector2_rule1' => value
, 'group3_selector2_rule2' => value
);
into this:
array(
'group1' => array(
'selector1' => array(
'rule1' => value
, 'rule2' => value
, 'rule3' => value
)
, 'selector2' => array(
'rule1' => value
, 'rule2' => value
)
) // end group 1
, 'group2' => array(
'selector1' => array(
'rule1' => value
, 'rule2' => value
)
) // end group 2
, 'group3' => array(
'selector1' => array(
'rule1' => value
)
, 'selector2' => array(
'rule1' => value
, 'rule2' => value
)
) // end group 3
); // end array
If anyone out there would like to suggest a smart way, I'd be interested :) I think I could labour some algorithm, but I'd like something elegant and have a feeling that some clever use of explode() and some 'array_merging' functions could do it?