取消设置多个数组
我的代码需要帮助。要从下面的数组中取消设置 xfer 数组:
if($_SESSION["s"]["user"]["typ"] == 'admin') {
$form["tabs"]['dns_soa'] = array (
'title' => "DNS Zone",
'width' => 100,
'template' => "templates/dns_soa_edit.htm",
'fields' => array (
##################################
# Begin Datatable fields
##################################
'xfer' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
'update_acl' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
'active' => array (
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOX',
'default' => 'Y',
'value' => array(0 => 'N',1 => 'Y')
),
##################################
# ENDE Datatable fields
##################################
)
);
}
我只是:
unset($form["tabs"]['dns_soa']['fields']['xfer']);
为了取消所有 3 个设置,我这样做了。更新 - 我实际上在“字段”中有很多数组,但我只提供了 3 个:
unset($form["tabs"]['dns_soa']['fields']['xfer']);
unset($form["tabs"]['dns_soa']['fields']['update_acl']);
unset($form["tabs"]['dns_soa']['fields']['active']);
无论如何,我是否可以在不编码的情况下取消设置许多数组 unset($form["tabs"]['dns_soa']['fields']数组名称);
多次?提前致谢。
更新 - 抱歉,我应该提供更多信息。如何禁用 3 中的 2 阵列?例如,只需禁用 ['xfer'] 和 ['active']?
I need help with my code. To unset xfer array from array below:
if($_SESSION["s"]["user"]["typ"] == 'admin') {
$form["tabs"]['dns_soa'] = array (
'title' => "DNS Zone",
'width' => 100,
'template' => "templates/dns_soa_edit.htm",
'fields' => array (
##################################
# Begin Datatable fields
##################################
'xfer' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
'update_acl' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'width' => '30',
'maxlength' => '255'
),
'active' => array (
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOX',
'default' => 'Y',
'value' => array(0 => 'N',1 => 'Y')
),
##################################
# ENDE Datatable fields
##################################
)
);
}
I just:
unset($form["tabs"]['dns_soa']['fields']['xfer']);
and to unset all 3 I do this. UPDATE - I have many array in 'fields' actually but I just provide 3:
unset($form["tabs"]['dns_soa']['fields']['xfer']);
unset($form["tabs"]['dns_soa']['fields']['update_acl']);
unset($form["tabs"]['dns_soa']['fields']['active']);
Is there anyway I could unset many array without codingunset($form["tabs"]['dns_soa']['fields']array name here);
many times? Thanks in advance.
UPDATE - My apologies I should provide more information. How do you disable 2 out of 3 array? For example just disable ['xfer'] and ['active']?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以只说:
或
更新:
要仅取消设置键的特定子集而不在代码中多次重复
unset
,我会执行一个循环:You can just say:
or
UPDATE:
To unset only a particular subset of the keys without repeating
unset
many times in the code, I would do a loop:如果您打算经常使用它,您可以创建一个函数来帮助简写它:
If it's something you plan on using frequently, you could just create a function to help shorthand it:
如果您想取消设置
fields
中的所有子数组,您可以使用:编辑:在这种情况下,您能做的最好的事情就是使用for或foreach。
If you want to unset all the subarray in
fields
, you can use:Edit: In this case the best you can do is to use a for or foreach.