title: php - search an array for a string
body: <pre><code>&lt;?php // SEARCH TAGS FOR A SPECIFIC TAG
    $tags = CollectionAttributeKey::getByHandle('recipe_tags'); // attribute handle of tags to search
    $tagToFind = 'Videos'; // declare the specific tag to find
    $selectedTags = array($page-&gt;getAttribute($tags-&gt;getAttributeKeyHandle())); // get tags associated with each page and put them in an array
  
    foreach ($selectedTags as $tag) { // output tags separately
  
      echo $tag; // ECHO TEST - check that individual tags associated with each page are outputting correctly
  
      if ($tag == $tagToFind) { // if $tag is equal to $tagToFind
        echo ' Found';
      } else {
        echo ' Not found';
        }
    }
  ?&gt;
  </code></pre>
  
  <p><code>echo $tag;</code> outputs the list of tags associated with each page so I'm pretty sure the issue is how I'm checking if 'Videos' is in the list of tags.</p>
  
  <p>The above outputs the following list: <code>Breakfast</code> <code>Brunch</code> <code>Budget</code> <code>Meal</code> <code>Easy</code> <code>Lunch</code> <code>Quick Meals</code> <code>Supper</code> <code>Vegetarian</code> <code>Videos</code> and <code>Not found</code> even though Videos is in the list.</p>
  
  <p>I've also tried using in_array to look for 'Videos' like this:</p>
  
  <pre><code>if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict
    echo ' Found';
  } else { 
      echo ' Not found';
    }
  </code></pre>
  
  <p>But get the same result - I'm new to php so sorry if this is easy.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Cheers</p>