Check array for partial match (PHP) [duplicate]

不想你离开。 提交于 2019-12-05 13:56:04
Amal Murali
$filenames = array("120_120_435645.jpg","150_150_312312.jpg","250_250_1232327.jpg");
$matches = preg_grep("/312312/", $filenames);
print_r($matches);

Output:

Array
(
    [1] => 150_150_312312.jpg
)

Or, if you don't want to use regex, you can simply use strpos as suggested in this answer:

foreach ($filenames as $filename) {
    if (strpos($filename,'312312') !== false) {
    echo 'True';
    }
}

Demo!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!