Reputation: 1309
Why cant I do constant arrays in PHP 7? When I executing this code:
define(‘WEEKDAYS’, [ ‘Mon’, ‘Tue’ , ‘Wed’ , ‘Thu’ , ‘Fri’ ] );
var_dump(WEEKDAYS);
echo PHP_VERSION;
I get:
string(8) "WEEKDAYS"
7.0.0
Upvotes: 1
Views: 2220
Reputation: 1535
You're not using the right syntax:
//Simple array
define("CONSTANT_ARRAY", ['one', 'two', 'three',]);
//Multidimensional array
define("CONSTANT_ARRAY_MULTIDIMENSIONAL", [
'fruits' => ['pear', 'apple', 'pineapple',],
'cars' => ['mustang', 'chevette', 'ferrari',],
'games' => ['streetfighter', 'lol', 'dota',],
]);
//Inside class you must use const keyword
const MYCONSTANT = ['pear', 'apple', 'pineapple',];
Upvotes: 5