Constant arrays

suggest change

Arrays can be used as plain constants and class constants from version PHP 5.6 onwards:

Class constant example

class Answer {
    const C = [2,4];
}

print Answer::C[1] . Answer::C[0]; // 42

Plain constant example

const ANSWER = [2,4];
print ANSWER[1] . ANSWER[0]; // 42

Also from version PHP 7.0 this functionality was ported to the define function for plain constants.

define('VALUES', [2, 3]);
define('MY_ARRAY', [
    1,
    VALUES,
]);

print MY_ARRAY[1][1]; // 3

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents