Get all array keys that is not equal to X
Question by Oyvind Andersson
I have several files uploaded with a form that is processed by a PHP script. There are several “categories” that I need to have handles separate ways. In other words, I need some of the files in the $_FILES array to be stored someplace, and some others stored in other places.
So what I need is all files (array keys) that are not $_FILES[‘filename_form’] to be stored / used separably.
The reason why I need this is because the amount of files being uploaded are dynamic, but always either $_FILES[‘filename_type1’] or $_FILES[‘filename_type2_*] where * is a number that increments when more files are input from the form (dynamically)
Might be a very simple solution, either I’m too tired or maybe I’ve been staring too much at the code, but all I know is I need a solution before tomorrow morning, so it’s time sensitive =P
Appreciate all the help I can get.
Thank you!
Answer by Zombaya
$files = array();
$filenames = array();
foreach($_FILES as $name => $fileInfo)
{
if($name != 'filename_form')
{
$files[$name] = $fileInfo;
$filenames[] = $name;
}
}
Answer by Starx
Here is an alternate way
$keys = array_keys($thearray);
$filteredArray = array_filter($keys, 'fiterKeys');
function filterKeys($item) {
if($item != 'valuetocheck') return true;
else return false;
}