php阅读发布的数组

时间:2013-03-21 10:41:58

标签: php wordpress http-post

这可能是一个简单的问题,但我已经尝试了几个小时没有得到任何结果:

我正在定制一个开源WordPress插件。当我在我的自定义PHP文件和var_dump() $_POST变量上发布时,我得到以下内容:

array(7) { 
    ["hellomail"] => array(3) { 
        ["email"] => array(7) { 
            ["subject"]       => string(4) "asda" 
            ["from_name"]     => string(14) "Myplugin" 
            ["from_email"]    => string(12) "myplugin@myplugin.com" 
            ["replyto_name"]  => string(14) "Test" 
            ["replyto_email"] => string(12) "myplugin@myplugin.com" 
            ["params"]        => array(1) { 
                ["schedule"] => array(2) { 
                    ["day"] => string(10) "2013/03/21" 
                    ["time"] => string(8) "00:00:00" 
                } 
            } 
            ["email_id"] => string(2) "25" 
        } 
        ["campaign_list"] => array(1) { 
            ["list_id"] => array(1) { 
                [0] => string(1) "4" 
            } 
        } 
        ["campaign"] => array(1) { 
            ["campaign_id"] => string(2) "24" 
        } 
    } 
    ["receiver-preview"] => string(10) "myplugin@myplugin.com" 
    ["_wpnonce"]         => string(10) "999938595d" 
    ["_wp_http_referer"] => string(66) "/wp-admin/admin.php?page=testpage&action=editDetails&id=25" 
    ["action"]           => string(8) "savelast" 
    ["roll_redir"]       => string(0) "" 
    ["submit-send"]      => string(6) "Senden" 
} 

我需要的是["campaign_id"]["list_id"]。我真的不知道如何获得这些值,是否有一种简单的方法来访问它们?

2 个答案:

答案 0 :(得分:2)

php的世界=)

echo $_POST["hellomail"]["campaign_list"]["list_id"]; // to get array
echo $_POST["hellomail"]["campaign_list"]["list_id"][0]; // to get first
echo $_POST["hellomail"]["campaign"]["campaign_id"];

答案 1 :(得分:2)

这是数组的外观:

array(7) { 
    ["hellomail"]=> array(3) { 
        ["email"]=> array(7) { 
            ["subject"]=> string(4) "asda" 
            ["from_name"]=> string(14) "Myplugin" 
            ["from_email"]=> string(12) "myplugin@myplugin.com" 
            ["replyto_name"]=> string(14) "Test" 
            ["replyto_email"]=> string(12) "myplugin@myplugin.com" 
            ["params"]=> array(1) { 
                ["schedule"]=> array(2) { 
                    ["day"]=> string(10) "2013/03/21" 
                    ["time"]=> string(8) "00:00:00" 
                } 
            } 
            ["email_id"]=> string(2) "25" 
        } 
        ["campaign_list"]=> array(1) { 
            ["list_id"]=> array(1) { 
                [0]=> string(1) "4" 
            } 
        } 
        ["campaign"]=> array(1) { 
            ["campaign_id"]=> string(2) "24" 
        } 
    } 
    ["receiver-preview"]=> string(10) "myplugin@myplugin.com" 
    ["_wpnonce"]=> string(10) "999938595d" 
    ["_wp_http_referer"]=> string(66) "/wp-admin/admin.php?page=testpage&action=editDetails&id=25" 
    ["action"]=> string(8) "savelast" 
    ["roll_redir"]=> string(0) "" 
    ["submit-send"]=> string(6) "Senden" 
} 

尝试使用以下代码段来获取您要查找的特定数组元素。

echo $_POST["hellomail"]["campaign_list"]["list_id"][0]."<br/>"
    .$_POST["hellomail"]["campaign"]["campaign_id"];