Skip to content

Instantly share code, notes, and snippets.

@mdsahib
Created November 12, 2012 19:10
Show Gist options
  • Save mdsahib/4061240 to your computer and use it in GitHub Desktop.
Save mdsahib/4061240 to your computer and use it in GitHub Desktop.
Shorthand to check value in array
<?php
//this array maps the function with the get parameters
$functions = array (
"action" => "do_actions" ,
"filter" => "do_filters"
);
foreach ($_GET as $key=>$value) {
//check if this field is corresponding functions or not
if ( array_key_exists($key , $functions) ) {
call_user_func($functions[$key] , $key,$value);
}
}
function do_actions ($key , $value) {
//place your code here to play with this value
echo 'do_actions is called with ' . $key . 'and' . $value . "</br>";
}
function do_filters ($key , $value) {
//place your code here to play with this value
echo 'do_filters is called with ' . $key . ' and ' . $value . "</br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment