I have an array about 1500 entries worth of file paths.
Some of them are in a sub directory which I want to remove, say "SUB/". For optimization's sake, which is the best option?
Foreach ($key=>$val)and string update$array[$key] = str_replace("_SUB_/","",$val);- Same as above, but do a if/then to only run the str_replace if the string starts with "SUB/"
- Implode the array to a single string, run str_replace on that string, and then explode it back to an array
- Something else I'm not thinking of
None of this matters much on my dev machine, but I'm intending to ultimately run it off a Raspberry Pi, so the more optimal I can get it, the better.
Update: I was not aware that str_replace worked directly on arrays, in that case, just two options then
- Use str_replace on array
- Implode, use str_replace on string, Explode
str_replaceitself will allow you to pass an array as the subject. "If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well." php.net/str_replace Donestr_replaceaccepted & returned arrays! Thanks :)