2012-08-01 56 views
0

我想在我的wordpress选项中回显数组第二级的设置,并且在获取变量时遇到了一些麻烦。此代码的工作:Php数组:我如何回显这个值?

<?php foreach($area['fields'] as $field): ?> 
<?php if ($field['id'] == 'show_border') 
    {echo ' show_border';} ?> 
<?php endforeach; ?> 

这只是检查是否存在,如果你想显示边框,询问现场,如果有它的回声我想做的事情,无论什么领域是设定在实际显示边界与否。

我想要做的只是回显设置在“show_border”字段中的值。

任何想法我会怎么做?

编辑

array(11) { 
    [0]=> 
    array(3) { 
    ["name"]=> 
    string(10) "# of posts" 
    ["id"]=> 
    string(5) "posts" 
    ["type"]=> 
    string(4) "text" 
    } 
    [1]=> 
    array(5) { 
    ["name"]=> 
    string(13) "posts per row" 
    ["id"]=> 
    string(13) "posts_per_row" 
    ["type"]=> 
    string(6) "select" 
    ["default"]=> 
    int(3) 
    ["options"]=> 
    array(8) { 
     [1]=> 
     int(1) 
     [2]=> 
     int(2) 
     [3]=> 
     int(3) 
     [4]=> 
     int(4) 
     [5]=> 
     int(5) 
     [6]=> 
     int(6) 
     [7]=> 
     int(7) 
     [8]=> 
     int(8) 
    } 
    } 
    [2]=> 
    array(5) { 
    ["name"]=> 
    string(11) "header type" 
    ["id"]=> 
    string(13) "f_header_type" 
    ["type"]=> 
    string(6) "select" 
    ["default"]=> 
    string(2) "h4" 
    ["options"]=> 
    array(6) { 
     ["h1"]=> 
     string(2) "h1" 
     ["h2"]=> 
     string(2) "h2" 
     ["h3"]=> 
     string(2) "h3" 
     ["h4"]=> 
     string(2) "h4" 
     ["h5"]=> 
     string(2) "h5" 
     ["h6"]=> 
     string(2) "h6" 
    } 
    } 
    [3]=> 
    array(5) { 
    ["name"]=> 
    string(5) "icon?" 
    ["id"]=> 
    string(9) "show_icon" 
    ["type"]=> 
    string(5) "radio" 
    ["default"]=> 
    string(3) "yes" 
    ["options"]=> 
    array(2) { 
     ["yes"]=> 
     string(3) "yes" 
     ["no"]=> 
     string(2) "no" 
    } 
    } 
    [4]=> 
    array(5) { 
    ["name"]=> 
    string(13) "icon location" 
    ["id"]=> 
    string(13) "icon_location" 
    ["type"]=> 
    string(6) "select" 
    ["default"]=> 
    string(4) "left" 
    ["options"]=> 
    array(3) { 
     ["left"]=> 
     string(4) "left" 
     ["right"]=> 
     string(5) "right" 
     ["top"]=> 
     string(3) "top" 
    } 
    } 
    [5]=> 
    array(5) { 
    ["name"]=> 
    string(10) "show text?" 
    ["id"]=> 
    string(9) "show_text" 
    ["type"]=> 
    string(5) "radio" 
    ["default"]=> 
    string(3) "yes" 
    ["options"]=> 
    array(2) { 
     ["yes"]=> 
     string(3) "yes" 
     ["no"]=> 
     string(2) "no" 
    } 
    } 
    [6]=> 
    array(5) { 
    ["name"]=> 
    string(12) "show border?" 
    ["id"]=> 
    string(11) "show_border" 
    ["type"]=> 
    string(5) "radio" 
    ["default"]=> 
    string(2) "no" 
    ["options"]=> 
    array(3) { 
     ["top"]=> 
     string(3) "top" 
     ["bot"]=> 
     string(3) "bot" 
     ["no"]=> 
     string(2) "no" 
    } 
    } 
    [7]=> 
    array(5) { 
    ["name"]=> 
    string(8) "category" 
    ["id"]=> 
    string(8) "category" 
    ["type"]=> 
    string(6) "select" 
    ["multiple"]=> 
    bool(true) 
    ["options"]=> 
    array(2) { 
     [4]=> 
     string(7) "feature" 
     [3]=> 
     string(6) "slider" 
    } 
    } 
    [8]=> 
    array(4) { 
    ["name"]=> 
    string(14) "custom classes" 
    ["id"]=> 
    string(14) "custom_classes" 
    ["type"]=> 
    string(4) "text" 
    ["default"]=> 
    string(0) "" 
    } 
    [9]=> 
    array(5) { 
    ["name"]=> 
    string(10) "read more?" 
    ["id"]=> 
    string(9) "read_more" 
    ["type"]=> 
    string(5) "radio" 
    ["default"]=> 
    string(3) "yes" 
    ["options"]=> 
    array(2) { 
     ["yes"]=> 
     string(3) "yes" 
     ["no"]=> 
     string(2) "no" 
    } 
    } 
    [10]=> 
    array(4) { 
    ["name"]=> 
    string(14) "read more text" 
    ["id"]=> 
    string(14) "read_more_text" 
    ["type"]=> 
    string(4) "text" 
    ["default"]=> 
    string(16) "Continue reading" 
    } 
} 

我试图得到像[ “ID”] => “show_border” 的值和回声它的价值。

+0

'echo $ field ['show_border']' – Jon 2012-08-01 09:50:21

+0

是的,这是行不通的。 – 2012-08-01 09:52:20

+1

你的数组看起来像什么? – Dale 2012-08-01 09:53:27

回答

1

基本上你不能在PHP中获得表单值,你将从已经加载到服务器端的表单中选择。

这就像从未来走向过去。

您应该使用Javascript代码+ AJAX,而不是PHP,但它会更复杂。 不知道网站的完整来源,无法通过一个简单的答案告诉你。

另外它取决于你的开发技能。

+0

是的,我添加了一个var_dump到操作 – 2012-08-01 10:10:57

+0

我不太确定。我没有写出原始代码。您编写的代码输出默认值,但不是当前的值。我不认为它使用ajax来传递值,因为它不会改变,直到我更新wordpress中的帖子。 – 2012-08-01 10:47:30

+0

如果你的值不在那个数组中,你可以var_dump($ _ POST);当你提交表格时? – kenorb 2012-08-01 10:49:22