Dynamically Creating Functions : create_function « Functions « PHP






Dynamically Creating Functions

 
<?php
if (count($_POST) > 0) {
    $prepped = create_function('$a', 'return trim($_POST[$a]);');
}
elseif (count($_GET) > 0) {
    $prepped = create_function('$a', 'return strtoupper($_GET[$a]);');
}
else {
    $prepped = create_function('$a', 'return false;');
}

echo $prepped('file');
?>
  
  








Related examples in the same category

1.A Simple Anonymous Function