Remove all array elements that do not match specific condition

后端 未结 1 1021
既然无缘
既然无缘 2021-01-26 23:23

I\'ve been looking into array_map but not sure if this is the best way to do it.

I am currently getting the following array returned from my scandir

相关标签:
1条回答
  • 2021-01-26 23:41

    You should be looking at array_filter() instead

    $result = array_filter(
        $originalArray,
        function($value) {
            return (strpos($value, 'post-') === 0);
        }
    );
    

    Though using glob() rather than scandir() would have allowed you to do the filter while actually retrieving the directory list

    0 讨论(0)
提交回复
热议问题