Php数组:我怎样才能回应这个值呢?

时间:2012-08-01 09:48:51

标签: php arrays

我试图在wordpress选项中回显数组的第二级设置,并且在获取变量时遇到一些麻烦。这段代码可以工作:

 <?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”] =&gt;这样的值“show_border”并回显它的价值。

1 个答案:

答案 0 :(得分:1)

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

就像从未来走向过去。

你应该使用Javascript代码+ AJAX而不是PHP,但它会复杂得多。 如果不知道网站的完整来源,就不可能在一个简单的答案中告诉你。

这也取决于你的开发技巧。

相关问题