Welcome Guest, Not a member yet? Register   Sign In
extended array helper functions : array_key_matches_regex and array_key_matches_string
#2

[eluser]xwero[/eluser]
I should read more blogs or take the time to remember all the string functions php offers.

The preg_match in helper is replaced by strncasecmp.

Code:
/**
* Array match key - checks if the array key exists using a string
*
* @access    public
* @param    string
* @param    array
* @return    mixed
*/    
function array_key_matches_string($string,$array)
{
    $postkeys = array_keys($array);
    foreach($postkeys as $key)
    {
        if(strncasecmp($string,$key,strlen($string)) == 0)
        {
            return $key;
        }
    }
    return false;
}

now you can do
Code:
$updatematch = array_match_key('update_',$_POST);
if(is_string($updatematch))
{
   $id = str_replace('update_',0,$updatematch);
}

This way it's closer to the native php functions but you lose the flexibility regex offers. I have to look into the performance for the two functions.


Messages In This Thread
extended array helper functions : array_key_matches_regex and array_key_matches_string - by El Forum - 02-20-2008, 02:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB