Professional Documents
Culture Documents
PHP Dynamic Constants
PHP Dynamic Constants
constant you use depends on input from the user, you can use this method to pre-define your constants and then use them later in your code: <?php MIN_PRODUCT_PRICE = '4.00'; MAX_PRODUCT_PRICE = '40.00'; $types_array = array('maximum' => 'max', 'minimum' => 'min'); $prefix = strtoupper($types_array[$type]); $min_constant = constant("self::{$prefix}_PRODUCT_PRICE"); $max_constant = constant("self::{$prefix}_PRODUCT_PRICE");