[eluser]xwero[/eluser]
Because the array_key_exists doesn't support regular expressions i've made a function that does.
Code:
/**
* Array match key - checks if the array key exists using a regex
*
* @access public
* @param string
* @param array
* @return mixed
*/
function array_key_matches_regex($regex,$array)
{
$postkeys = array_keys($array);
foreach($postkeys as $key)
{
if(preg_match($regex,$key))
{
return $key;
}
}
return false;
}
It's useful for getting form buttons that have data added to their name.
Code:
$updatematch = array_match_key('/^update_/',$_POST);
if(is_string($updatematch))
{
$id = str_replace('update_',0,$updatematch);
}