我想从添加到cakephp中插入数据。我在$this->request->data['ProductValue']
中得到了数组在控制器处。我的阵列是:
Array
(
[0] => Array
(
[title] => Deepak1
[value] => Option1
)
[1] => Array
(
[title] => Deepak2
[value] => Ans1, Ans2, Ans3, Ans4
)
[2] => Array
(
[title] => Deepak3
[value] => Product1
)
[3] => Array
(
[title] => Deepak4
[value] => Radio1
)
)
但我需要这种类型的阵列:
Array
(
[0] => Array
(
[title] => Deepak1
[value] => Option1
)
[1] => Array
(
[title] => Deepak2
[value] => Array
(
[0] => Ans1
[1] => Ans2
[2] => Ans3
[3] => Ans4
)
)
[2] => Array
(
[title] => Deepak3
[value] => Product1
)
[3] => Array
(
[title] => Deepak4
[value] => Radio1
)
)
请告诉我怎么做。。。
function prepare(&$List) {
foreach($List as &$element) {
$tmp = explode(', ', $element['value']);
if(count($tmp) <= 1) { continue; }
$element['value'] = $tmp;
}
}
prepare($YourArray);