You are on page 1of 1

When you have constants that you need to read and use in your code (PHP) but which

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");

You might also like