我從一個崗位操作的陣列爆炸字符串數組
$country = $_POST['country']; //The number of countries differ according to the user selection
$c = count($country);
輸出:`
Array ([0] => England,69,93 [1] => Australia,79,84 [2] => Greece,89,73 [3] => Germany,59,73)`
我必須把它分解成一個多維數組,如:
> Array ([0] => Array ([0] => England [1] => 69 [2] => 93)
> [1] => Array ([0] => Australia [1] => 79 [2] => 84)
> [2] => Array ([0] => Greece [1] => 89 [2] => 73)
> [3] => Array ([0] => Germany [1] => 59 [2] => 73))
如何做到這一點在PHP
我試圖
$r = array();
foreach($country as &$r){
$r = explode(",", $r);
//for($i = 0; $i < count($country); $i++){
//for($j = 0; $j < count($r); $j++){
//$array[$i][$j] = $r;
//}
//}
}
echo '<br>';
print_r($r);
for循環也沒有工作,因此評論說出來,但如果需要離開它作爲一個選項。
打印功能現在只打印陣列1。不完全確定我做錯了什麼。任何幫助表示讚賞。謝謝
嘗試'的print_r($國家);'你的循環後,而不是 – Crisp 2013-03-23 11:51:44