Check if string equals, starts withs or ends with match
<p>How would I improve this functions for that is:
Searches an array for fields names which either:</p>

<ul>
<li>a) Exactly matches  </li>
<li>b) beings with "_" check if string begins with </li>
<li>c) ends with "_" check if string ends with</li>
</ul>

<p>E.g I have a list of column names:</p>

<pre><code>array(
    'customer_name',
    'customer_lastname',
    'customer_streetname',
    'customer_dob',
    'system_modified'
)
</code></pre>

<p>And another array with formatting conditions:</p>

<pre><code>array(
    '_dob' =&gt; 'date_dob',
    '_name' =&gt; 'varchar',
    'customer_name' =&gt; 'html_text',
    'system_' =&gt; 'required'
)
</code></pre>

<p>Results apply the conditions against the column names:</p>

<pre><code>1. customer_name = html_text (exact matches have higher preference)
2. customer_lastname = varchar
3. customer_streetname = 
4. customer_dob = dob
5. system_modified = required
</code></pre>

<p>Current have this:</p>

<pre><code>protected function matchPatterns($string) {
    $return = array();
    $parrerns = $this-&gt;_normaliseArrayItem($this-&gt;getPatterns());
    foreach ($parrerns as $match) {

        // If exact match
        if($string == $match) {
            $return[] = $match;
            break;
        // Else if begins with _ and ends with string.
        } elseif($string[0] == "_" &amp;&amp; substr_compare($string, $match, -strlen($match), strlen($match)) === 0) {
            $return[] = $match;
        }

    } // end loop
    return $return;
}


/**
 * Return an array of validation patterns.
 *
 * @return string[]
 */
public function getPatterns() {
    return $this-&gt;_patterns;
}


/**
 * Returns an item as array rather than single item.
 *
 * @param string[] $data
 * @return string[]
 */
protected function _normaliseArrayItem($data) {
    if(!isset($data[0])|| !is_array($data)) {
        $tmp[] = $data;
        $data = $tmp;
    }
    return $data;
}
</code></pre>
