2011-05-14 90 views
0

說我有一個多維數組是這樣的:如何在PHP 2維多維數組上移動X軸和Y軸?

$data[0]['country'] = Angola 
$data[0]['report'] = Food safety 

$data[1]['country'] = Angola 
$data[1]['report'] = Police 

$data[2]['country'] = Zimbabwe 
$data[2]['report'] = Water 

$data[3]['country'] = Angola 
$data[3]['report'] = Safety 

$data[4]['country'] = Tanzania 
$data[4]['report'] = Etc... 

什麼是最簡單的移軸,這樣我就必須

$data['country'][0] = Angola 
$data['country'][1] = Angola 
$data['country'][2] = Zimbabwe 
$data['country'][3] = Angola 
$data['country'][4] = Tanzania 

$data['report'][0] = Food safety 
$data['report'][1] = Police 
$data['report'][2] = Water 
$data['report'][3] = Safety 
$data['report'][4] = Etc... 

回答

0
$result = array(); 
foreach($data as $value){ 

    $result['country'][] = $value['country']; 
    $result['report'][] = $value['report']; 
} 
$data = $result; 
0
for ($i=0; $i < (count($data)/2); $i++) 
{ 
    $data['country'][$i] = $data[$i]['country']; 
    $data['report'][$i] = $data[$i]['report']; 
}