Search code examples
phpfile-type

How to assign the same value to all elements of an array


Sorry, I don't know how to really word this question. I have an app where you can specify filetypes to be hidden from certain users like so:

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

The above line would hide all .ftpquota files from user #108. I am trying to hide filetypes from ALL users. I have tried:

$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");

Would anyone have an idea as to how I can specify ALL users?


Solution

  • Since you don't know what all the indeces of the array are, you can just loop through all the values and set them all to the desired one using foreach.

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