【发布时间】:2017-06-22 07:35:58
【问题描述】:
这是我当前的数组,我想把这个数组转换成多维数组
Array
(
[question1] => My question 1
[options1] => My Option 1
[answer1] => Answer 1 goes here
[question2] => My question 2
[options2] => My Option 2
[answer2] => Answer 2 goes here
)
我希望我的数组如下所示。如何做到这一点,有什么建议吗?
Array
(
[0] => Array
(
[question1] => My question 1
[options1] => My Option 1
[answer1] => Answer 1 goes here
)
[1] => Array
(
[question2] => My question 2
[options2] => My Option 2
[answer2] => Answer 2 goes here
)
)
这是我的代码
$i=9;
$topicsArr=array();
$j = 1;
while ($row[$i]){
$topicsArr['question' .$j] = $row[$i];
$topicsArr['options' .$j] = $row[$i+1];
$topicsArr['answer' .$j] = $row[$i+2];
$i = $i +3;
$j++;
}
【问题讨论】:
标签: php arrays multidimensional-array associative-array