English 中文(简体)
A. 许多阵容
原标题:Unset many array

我需要帮助。 从以下阵列中分离微粒阵列:

    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. 在3个阵列中,你如何使2个分离? 例如,仅可加以区别[xfer]和[活性]?

最佳回答

You can just say:

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

// just to reset the fields array
$f或m["tabs"][ dns_soa ][ fields ] = array();

最新资料:

只排出一个特定的关键子组,而不重复unset 在《刑法》中,我有好几次:

f或each (array( xfer ,  active ) as $field) {
  unset($f或m["tabs"][ dns_soa ][ fields ][$field]);
}
问题回答

如果你计划经常使用,那么你就只能建立一种功能,帮助简便:

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

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

如果你想在<代码>领域/代码>上揭开所有亚拉,你可以使用:

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

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





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签