webkill Posted November 10, 2008 Share Posted November 10, 2008 Hey guys, check out this function. I have to filter out the array entries that have a certain word somewhere within the string. I've had ago myself using array_filter and in_array but i just cant do it. Can anyone help? Thanks function stt_getinfo() { global $post; $post_ID = $post->ID; $arr = array_unique(get_post_meta($post_ID, 'searchTerm')); $array2 = array_unique($arr); if(empty($array2)) { return false; } else { return $array2; } } Link to comment https://forums.phpfreaks.com/topic/132182-solved-in-str-array/ Share on other sites More sharing options...
flyhoney Posted November 10, 2008 Share Posted November 10, 2008 Yikes thats Wordpress isn't it? I don't quite understand what you are trying to do. Can you explain in a little more detail? Link to comment https://forums.phpfreaks.com/topic/132182-solved-in-str-array/#findComment-686985 Share on other sites More sharing options...
webkill Posted November 10, 2008 Author Share Posted November 10, 2008 Basically need to filter $array2. You could ignore rest of code i suppose. I have to filter out the array entries that have a certain word somewhere within the string. Link to comment https://forums.phpfreaks.com/topic/132182-solved-in-str-array/#findComment-686988 Share on other sites More sharing options...
flyhoney Posted November 10, 2008 Share Posted November 10, 2008 Try this: <?php function filter_array ($array, $certain_word) { $keep = array(); foreach ($array as $string) { if (strpos($string, $certain_word) === false) { $keep[] = $string; } } return $keep; } ?> Link to comment https://forums.phpfreaks.com/topic/132182-solved-in-str-array/#findComment-687000 Share on other sites More sharing options...
webkill Posted November 10, 2008 Author Share Posted November 10, 2008 Thank you. Link to comment https://forums.phpfreaks.com/topic/132182-solved-in-str-array/#findComment-687014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.