Php数组:我如何回显该数组的值?
我试图在wordpress选项中回显数组第二级的设置,但在获取变量时遇到了一些问题。此代码确实有效:Php数组:我如何回显该数组的值?,php,arrays,Php,Arrays,我试图在wordpress选项中回显数组第二级的设置,但在获取变量时遇到了一些问题。此代码确实有效: <?php foreach($area['fields'] as $field): ?> <?php if ($field['id'] == 'show_border') {echo ' show_border';} ?> <?php endforeach; ?> 我试图获取一个像[“id”]=>“show_border”这样的值,并回显它的值。基
<?php foreach($area['fields'] as $field): ?>
<?php if ($field['id'] == 'show_border')
{echo ' show_border';} ?>
<?php endforeach; ?>
我试图获取一个像[“id”]=>“show_border”这样的值,并回显它的值。基本上,您无法在PHP中获取表单值,您将从服务器端已加载的表单中选择该值 这就像从未来走向过去 您应该使用Javascript代码+AJAX,而不是PHP,但这将更加复杂。 如果不知道网站的全部来源,就不可能用一个简单的答案告诉你
这还取决于你的开发技能。你的数组看起来像什么?@BRAINBUZZmedia:“不工作”没有太大帮助。使用应该给我值的方法,例如“top”,我得到的是一些奇怪的东西,例如“p p f s s s c r r”,请在数组$field中添加一个转储,我们猜不出它的内容。你又想做什么?是的,我在opI中添加了一个var_转储,我不太确定。我没有写原始代码。您编写的代码输出默认值,但不是当前值。我不认为它是在使用ajax传递值,因为在我更新wordpress中的帖子之前,它不会改变。如果你的值不在该数组中,你能使用var\u dump($\u post)吗;提交表单时?嗯,它使用ajax保存输入的内容。您试图执行的foreach代码是在表单显示时、发布时还是在ajax请求期间?
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"
}
}