You're nearly there with your loop, however $value
is not a key within the $key
variable. If you print_r
your $keywords
you will see that the $key
variable will be the string on the left side of the =>
and the $value
on the right.
Quick Fix:
if( strlen($value) < 3 )
Better fix:
$keywords = array_filter($keywords, function($x) { return strlen($x) >= 3; });
Nested fix
$keywords = array_filter(explode(' ',strtolower($_POST)), function($x) { return strlen($x) >= 3; });
Alternate fix (if you have a too old version of PHP that you cant do the anonymous functions above)
$keywords = array_filter(explode(' ',strtolower($_POST)), create_function('$x', 'return strlen($x) >= 3;'));