如何为数组的所有元素分配相同的值

时间:2012-04-25 23:31:44

标签: php file-type

抱歉,我不知道如何真正说出这个问题。我有一个应用程序,您可以指定某些用户隐藏的文件类型,如下所示:

$config['app']['custom_hidden_files']['users']['108'] = array("*.ftpquota", "*.FTPQUOTA");

以上行将隐藏用户#108的所有.ftpquota文件。我试图隐藏所有用户的文件类型。我试过了:

$config['app']['custom_hidden_files']['users'][''] = array("*.ftpquota", "*.FTPQUOTA");
$config['app']['custom_hidden_files']['users'][] = array("*.ftpquota", "*.FTPQUOTA");
$config['app']['custom_hidden_files']['users']['*'] = array("*.ftpquota", "*.FTPQUOTA");
$config['app']['custom_hidden_files']['users'][*] = array("*.ftpquota", "*.FTPQUOTA");
$config['app']['custom_hidden_files']['users'] = array("*.ftpquota", "*.FTPQUOTA");

有人会知道如何指定所有用户吗?

2 个答案:

答案 0 :(得分:3)

由于您不知道数组的所有索引是什么,您可以循环遍历所有值并使用foreach将它们全部设置为所需的值。

foreach($config['app']['custom_hidden_files']['users'] as $index => $value)
{
    $config['app']['custom_hidden_files']['users'][$index] = Array("*.ftpquota", "*.FTPQUOTA");
}

答案 1 :(得分:1)

 foreach ($config['app']['custom_hidden_files']['users'] as $user)
 {
    $user=array("*.ftpquota", "*.FTPQUOTA");
 }
相关问题