0
陣列選擇陣列值:從得到這個數組索引
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]];
}
輸出是不是我想要的所有..
EDIT2:
嘗試過這樣的事情:
$output_array[$i] = array_push($array1[$i][$index_array[$i][1]]);
$output_array[$i] = array_push($array1[$i][$index_array[$i][2]]);
但沒有工作..
通常它是有一些培訓,爲自己的陣列後進行。只是玩弄它而不是問這樣的本地化問題(不要把它個人化;) – hek2mgl 2013-05-07 06:14:01
SO不是讓人們爲你寫代碼,你必須先做出一些努力。顯示你的嘗試,我們會幫你解決問題。 – Barmar 2013-05-07 06:22:58
我嘗試使用'foreach'和'for'循環,不適當的編輯操作與即時通訊嘗試atm .. – Edgar 2013-05-07 06:24:23