取消设置多个数组

发布于 2024-12-11 13:05:06 字数 1863 浏览 0 评论 0原文

我的代码需要帮助。要从下面的数组中取消设置 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 coding
unset($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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生寂 2024-12-18 13:05:06

您可以只说:

// to unset the parent "fields" array, which includes xfer, update_acl and active
unset($form["tabs"]['dns_soa']['fields']);

// just to reset the fields array
$form["tabs"]['dns_soa']['fields'] = array();

更新:

要仅取消设置键的特定子集而不在代码中多次重复 unset ,我会执行一个循环:

foreach (array('xfer', 'active') as $field) {
  unset($form["tabs"]['dns_soa']['fields'][$field]);
}

You can just say:

// to unset the parent "fields" array, which includes xfer, update_acl and active
unset($form["tabs"]['dns_soa']['fields']);

or

// just to reset the fields array
$form["tabs"]['dns_soa']['fields'] = array();

UPDATE:

To unset only a particular subset of the keys without repeating unset many times in the code, I would do a loop:

foreach (array('xfer', 'active') as $field) {
  unset($form["tabs"]['dns_soa']['fields'][$field]);
}
温柔一刀 2024-12-18 13:05:06

如果您打算经常使用它,您可以创建一个函数来帮助简写它:

<?php
function unset_array($keys, &$arr) {
    foreach($keys as $key) {
        unset($arr[$key]);
    }
}

unset_array(array('xfer', 'active'), $arr['tabs']['dns_soa']);
?>

If it's something you plan on using frequently, you could just create a function to help shorthand it:

<?php
function unset_array($keys, &$arr) {
    foreach($keys as $key) {
        unset($arr[$key]);
    }
}

unset_array(array('xfer', 'active'), $arr['tabs']['dns_soa']);
?>
爱的十字路口 2024-12-18 13:05:06

如果您想取消设置fields中的所有子数组,您可以使用:

unset($form["tabs"]['dns_soa']['fields']);

编辑:在这种情况下,您能做的最好的事情就是使用for或foreach。

If you want to unset all the subarray in fields, you can use:

unset($form["tabs"]['dns_soa']['fields']);

Edit: In this case the best you can do is to use a for or foreach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文