title: PHP Search in Array
body: <p>We have an array, for example:</p>
  
  <pre><code>$my_array = array('Software Engineering', 'Civil Engineering', 'Hardware Engineering', 'BL AH Engineering');
  </code></pre>
  
  <p>Now I have a "$q" variable, I want to search between values of the array, remove the keys which doesn't contain $q, here is my code:</p>
  
  <pre><code>foreach($my_array as $key =&gt; &amp;$value){
      if (stripos(($value), $q) === false){
          unset($my_array[$key]);
      }
  }
  </code></pre>
  
  <p>now if we set the $q = 'eer':</p>
  
  <pre><code>var_dump($my_array);
  array
    0 =&gt; string 'Software Engineering' (length=20)
    1 =&gt; string 'Civil Engineering' (length=17)
    2 =&gt; string 'Hardware Engineering' (length=20)
    3 =&gt; &amp;string 'BL AH Engineering' (length=17)
  </code></pre>
  
  <p>as you see, nothing is removed since all the $values have 'eer' in 'Engineering'
  it's OK, but now I set <code>$q = 'eer civil'</code>, now:</p>
  
  <pre><code>var_dump($my_array);
  array
    empty
  </code></pre>
  
  <p>all the items are removed, but actually the 'Civil Engineering' contains both the 'eer' and 'civil', so it should not be removed, how I could make this work? I may explode the $q with ' space ' but it's not working.</p>
  
  <p>Thanks in advance</p>