- print_r: documentation ( source)
- strrpos: documentation ( source)
<?php
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
$mustcontain = 'url/sub/dir/';
$links = array (
0 => 'url/sub/dir/1234',
1 => 'url/sub/dir/',
2 => 'url/13214124',
3 => 'url/sub/123123123123',
);
$finalArr = array();
foreach($links as $v){
if(startsWith($v, $mustcontain)){
$finalArr[] = $v;
}
}
print_r($finalArr);