Advertisement
jessicakennedy1028

Constants through an Array

Sep 12th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. $defines = array(
  2.         "DEFKEY"=>"upper", # Options are upper or lower
  3.        "VERSION"=>"0.2.1", # Define a version
  4.        "BUILD"=>"65", # and or define a build number
  5.        "ENVIRONMENT" => "DEBUG", # Assigned is Debug, QA, Production
  6.        "CLI" => false,
  7.         "N" => "\n",
  8.         "BRN" => "<br />\n",
  9.         "BR" => "<br />",
  10.         "T" => "\t",
  11.         "DS" => DIRECTORY_SEPARATOR, # Are you on a Windows or Linux machine, let PHP handle the Directory Separator
  12.        "ROOT" => str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, getcwd())
  13.     );
  14.  
  15. # By assigning an array with keys you can give the ole define a quick and easy method to generate you most commonly used variables across all functions, classes, and just about anything else you throw at it.
  16.  
  17. # To define everything, now it is as simple as assigning them with a foreach loop
  18.  
  19. foreach ($defines as $key => $value) (!defined($key) ? define($key, $value) : die('Invalid constant '.$key));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement