2013-05-17 66 views
0

我想從表單發佈創建一個多維數組。這是該職位的轉儲:從PHP表單創建數組

array(8) { 
    ["check"]=> 
    int(1) 
    ["option_page"]=> 
    string(19) "content_boxes_group" 
    ["action"]=> 
    string(6) "update" 
    ["_wpnonce"]=> 
    string(10) "0adb157142" 
    ["_wp_http_referer"]=> 
    string(39) "/wp-admin/themes.php?page=home-settings" 
    ["title"]=> 
    array(3) { 
    [1]=> 
    string(9) "Downloads" 
    [2]=> 
    string(7) "Columns" 
    [3]=> 
    string(4) "Apps" 
    } 
    ["id"]=> 
    array(3) { 
    [1]=> 
    string(21) "k2-settings-downloads" 
    [2]=> 
    string(19) "k2-settings-columns" 
    [3]=> 
    string(16) "k2-settings-apps" 
    } 
    ["order"]=> 
    array(3) { 
    [1]=> 
    string(1) "1" 
    [2]=> 
    string(1) "2" 
    [3]=> 
    string(1) "3" 
    } 
} 

我想使它看起來像這樣:

array(
    array('title' => 'Downloads', 'id' => 'k2-settings-downloads', 'order' => '1'), 
    array('title' => 'Columns', 'id' => 'k2-settings-columns', 'order' => '2'), 
    array('title' => 'Apps', 'id' => 'k2-settings-apps', 'order' => '3') 
); 

我怎樣才能做到這一點?

+1

可能複製http://stackoverflow.com/questions/3813881/php-array-to-multidimensional-array的 – underscore

+1

沒有任何重複。至少它不是http://stackoverflow.com/questions/3813881/php-array-to-multidimensional-array的重複 – ncm

回答

1

這樣的事情?

$post = $_POST['your_array']; 
$output = array(); 
$titles = $post['title']; 
$ids = $post['id']; 
$orders = $post['order']; 
foreach($titles as $id => $title){ 
    $output[] = array("title"=>$title,"id"=>$ids[$id],'order'=>$orders[$id]); 
}