jessicakennedy1028 icon

Constants through an Array

jessicakennedy1028 | PRO | 09/12/18 10:01:56 AM UTC | 0 ⭐ | 347 👁️ | Never ⏰ | []
PHP |

970 B

|

None

|

0 👍

/

0 👎

$defines = array(
        "DEFKEY"=>"upper", # Options are upper or lower
        "VERSION"=>"0.2.1", # Define a version
        "BUILD"=>"65", # and or define a build number
        "ENVIRONMENT" => "DEBUG", # Assigned is Debug, QA, Production
        "CLI" => false,
        "N" => "\n",
        "BRN" => "<br />\n",
        "BR" => "<br />",
        "T" => "\t",
        "DS" => DIRECTORY_SEPARATOR, # Are you on a Windows or Linux machine, let PHP handle the Directory Separator
        "ROOT" => str_replace(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, getcwd())
    );
 
# 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.
 
# To define everything, now it is as simple as assigning them with a foreach loop
 
foreach ($defines as $key => $value) (!defined($key) ? define($key, $value) : die('Invalid constant '.$key));

Comments