I am looking for a way to optimize my script, i really think there will be a better way to do it but i cant think how...
Basically, i have a script that assigns a variable depending on a file name, like so:
Code: Select all
$file = substr($files_value, 0, 5);
if ($file == "90210") {
$fpid = 994;
}
$file = substr($files_value, 0, 16);
if ($file == "Filename.Version") {
$fpid = 992;
}
$file = substr($files_value, 0, 9);
if ($file == "Something") {
$fpid = 956;
}
Is there someway else i can do this? I know that if the file names were of the same length you could use a simple array $fpid = $array['$file'] but thats where the problem is - different lengths of filenames means the actual string length changes each time.
It would be nice to use an array, such as $files = array("90210", "Filename.Version", "Something", ...) but i dont see how i can easily do this with different length filenames.
Anyone able to offer some sugestions?
Thanks!