I would do this
$images =[
'/tmp/php59iuBb', '/tmp/phpdRewVH', 'PicturesI.jpg', 'Screenshot.png'
];
$images = preg_grep('~^(?!/tmp/)~', $images);
print_r($images);
Output
Array
(
[2] => PicturesI.jpg
[3] => Screenshot.png
)
Sandbox
Simple right!
Preg grep runs a regular expression against an array and returns the matches.
In this case
~^(?!/tmp/)~
negative lookbehind - insures that the match does not start with /tmp/
Which leaves us what we want.
Another option is
$images = array_filter($images,function($image){
return substr($image, 0, 5) != '/tmp/';
});
If you are not feeling the Regex love.
Sandbox
PS I love preg_grep its often overlooked for easier to understand but much more lengthy code. Preg Filter is another one of those, which you can use to prefix or suffix an entire array. For example I've used it to prepend paths to an array of filenames etc. For example it's this easy:
$images =[
'/tmp/php59iuBb', '/tmp/phpdRewVH', 'PicturesI.jpg', 'Screenshot.png'
];
print_r(preg_filter('~^(?!/tmp/)~', '/home/images/', $images));
//or you can add a whole image tag, if you want, with a capture group (.+) and backrefrence \1
print_r(preg_filter('~^(?!/tmp/)(.+)~', '<img src="/home/images/\1" />', $images));
Output
Array
(
[2] => /home/images/PicturesI.jpg
[3] => /home/images/Screenshot.png
)
Array
(
[2] => <img src="/home/images/PicturesI.jpg" />
[3] => <img src="/home/images/Screenshot.png" />
)
Sandbox
I thought you may find that "trick" useful as you can remove the bad ones and add a path to the good at the same time. They are worth checking out.
http://php.net/manual/en/function.preg-grep.php
http://php.net/manual/en/function.preg-filter.php
I feel like I should mention the same holds true for matching a file extension, which may also be useful, but I will leave that for another day.
Cheers!