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

[eluser]xwero[/eluser]
@Pygon: you can do this in one line
Code:
$needle = 'test';
$keys = array_keys($somearray);
if(in_array($needle,$keys)) // here the magic happens
{
   // do something with the array and the key
}
This way you only have to do one function call to get the array keys.

The main reason why i have written the functions is because sometimes i append data to my button names which makes it impossible to check them with php native functions. And because the buttons are created dynamically i can't hardcode the button action.
Code:
&lt;input type="submit" name="update_1" value="Update"&gt;<br>
&lt;input type="submit" name="update_2" value="Update"&gt;
I could do the same as in the first snippet and make the second parameter the keys array which saves me a function call but i know my lazy self and i will end up doing
Code:
array_key_matches_string('update_',array_keys($_POST));
Oh well use it any way you want the functions are up for grabs Smile


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



Theme © iAndrew 2016 - Forum software by © MyBB