title: Checking if an array key contains a value?
body: <p>I have an array, I want to check if the keys have '-main' after them.</p>
  
  <pre><code>foreach ($data as $key =&gt; $value) {
      if (substr($key, -5) == '-main'){
          ....
      }
  }
  </code></pre>
  
  <p>If they do have '-main' I then want to get the text prior to '-main'. I do:</p>
  
  <pre><code>$myVar = substr($key, 0, -5);
  </code></pre>
  
  <p>Is there a more efficient way of splitting the key so I don't have to do two sub strings?
  Perhaps I do not want to use '-main' any more and want to use a different length search item, perhaps as a variable. I would then have to do a character count rather than specifying -5. Is there a way to incorporate a variable without having to do character counts?</p>