1

Currently I can able to create constant variable in Codeigniter, but is there any way to create constant array in CI. Suppose I can create constant array of Languages supported by my website.

$language = array('English', 'French');
  • 1
    https://stackoverflow.com/questions/1290318/php-constants-containing-arrays/27413238#27413238 – Atural Jun 13 '17 at 08:13
  • it's not related to codeignter, constant arrays is related to php syntax it self, and YES, as long as your php version is higher than 5.6 you can use constant array http://php.net/manual/en/migration56.new-features.php – hassan Jun 13 '17 at 08:13

2 Answers2

4

In your constants.php located in your application/config folder simply declare it as

defined('LANGUAGE') OR define('LANGUAGE', array('English', 'French'));

Use can use them as

foreach (LANGUAGE as $key => $value) {
  echo $value;
}
Vipin
  • 41
  • 4
2

in your config->constants.php

$config['language'] = 'english';
$config['language'] = 'french';
Exprator
  • 26,992
  • 6
  • 47
  • 59