I am trying to work out how to use array filter to remove strings from array below a certain length.
Basicly I want to recreate this with array filter,
if( strlen($news_ps[$x]) < 5))
{
remove this string from array
}
$result = array_filter(
$originalArray,
function ($value) {
return strlen($value) >= 5;
}
);
EDIT
If you want to reorder the indexes as well, then just wrap the whole in a call to array_values()
$result = array_values(
array_filter(
$originalArray,
function ($value) {
return strlen($value) >= 5;
}
)
);
function lessthan5($v){
if(intval($v) > 5){
return $v;
}
}
print_r(array_filter(array(3,4,5,6,7) ,"lessthan5"));
//out put
Array ( [3] => 6 [4] => 7 )