Categories
PHP / MySQL

PHP7 – PHP Constants Containing Arrays

You can define a constant by using the define() function or by using the const keyword outside a class definition as of PHP 5.3.0. Once a constant is defined, it can never be changed or undefined.

Only scalar data (Boolean, integer, float and string) can be contained in constants prior to PHP 5.6. The ability to define array constants and define a constant as a scalar expression was introduced in PHP 5.6 using the const keyword. This ability has now been applied to the define() function too in the PHP7.It is possible to define constants as a resource, but it should be avoided, as it can cause unexpected results.

If you want to get all defined constants list you can use get_defined_constants()

By Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.

Leave a Reply

Your email address will not be published. Required fields are marked *