得到这个数组:
Array
(
[0] => Array
(
[0] => Array
(
[correct] =>
[answer] => false answer1
)
[1] => Array
(
[correct] =>
[answer] => false answer2
)
[2] => Array
(
[correct] =>
[answer] => false answer3
)
[3] => Array
(
[correct] => 1
[answer] => correct answer
)
)
[1] => Array
(
[0] => Array
(
[correct] =>
[answer] => false answer1
)
[1] => Array
(
[correct] =>
[answer] => false answer2
)
[2] => Array
(
[correct] =>
[answer] => false answer3
)
[3] => Array
(
[correct] => 1
[answer] => correct answer
)
)
)
并得到一组索引:
Array
(
[0] => Array
(
[0] => 0
[1] => 1
[2] => 2
)
[1] => Array
(
[0] => 0
[1] => 1
[2] => 2
)
)
我想得到的输出:
Array
(
[0] => Array
(
[0] => Array
(
[correct] =>
[answer] => false answer1
)
[1] => Array
(
[correct] =>
[answer] => false answer2
)
[2] => Array
(
[correct] =>
[answer] => false answer3
)
)
[1] => Array
(
[0] => Array
(
[correct] =>
[answer] => false answer1
)
[1] => Array
(
[correct] =>
[answer] => false answer2
)
[2] => Array
(
[correct] =>
[answer] => false answer3
)
)
)
如您所见,我想从第一个数组中选择所有值,具体取决于第二个数组的索引。我怎么做?
编辑:
这是我现在尝试解决的方法:
for($i = 0; $i < count($array1); $i++){
$output_array[] = $array1[$i][$index_array[$i][0]];
$output_array[] = $array1[$i][$index_array[$i][1]];
$output_array[] = $array1[$i][$index_array[$i][2]];
}
输出根本不是我想要的..
编辑2:
尝试过这样的事情:
$output_array[$i] = array_push($array1[$i][$index_array[$i][1]]);
$output_array[$i] = array_push($array1[$i][$index_array[$i][2]]);
但没有工作..