Jump to content

[SOLVED] In str array


webkill

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.