-4

I want to check if some word already exists in a array, for example 'kijken'.

This word does not exists in the array and I want to add it.

How do I make a check if the word exists?

My array looks like this:

Array
(
    [0] => vegen
    [1] => veeg
)
Array
(
    [0] => staan
    [1] => sta
)
gen_Eric
  • 223,194
  • 41
  • 299
  • 337

1 Answers1

3

The already classic function:

function in_array_r($needle, $haystack, $strict = false) {
  foreach ($haystack as $item) {
    if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
        return true;
    }
}

return false;
}

$term = 'kijken';

if ( in_array_r($term,$yourarray) == true ) {
     //do stuff
} else {
    echo $term.' not in array';
}
Peter Noble
  • 675
  • 10
  • 21