0

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

我正在定制一个开源 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"]。我真的不知道如何获得这些值,有没有简单的方法来访问它们?

4

2 回答 2

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"];
于 2013-03-21T10:56:51.137 回答
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"];
于 2013-03-21T10:57:05.537 回答