2017-06-13 08:11
浏览 218


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

图片转代码服务由CSDN问答提供 功能建议

目前我可以在Codeigniter中创建常量变量,但有没有办法在CI中创建常量数组。 假设我可以创建我的网站支持的常量语言数组。

  $ language = array('English','French'); 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dtcyv3985 2017-06-13 08:21

    You can serialize your array and then put it into the constant. For example,

    # define constant, serialize array 
    define ("FRUITS", serialize (array ("apple", "cherry", "banana"))); 

    Use it $my_fruits = unserialize (FRUITS);

    You can store it as a JSON string in a constant. And application point of view, JSON can be useful in other cases. 

    define ("FRUITS", json_encode(array ("apple", "cherry", "banana"))); 
    $fruits = json_decode (FRUITS); var_dump($fruits);

    Let me know if it not works.

    Note : This need PHP 5.6+ version

    解决 无用
    打赏 举报
  • doujumiao5024 2017-06-13 08:14

    in your config->constants.php

    $config['language'] = 'english';
    $config['language'] = 'french';
    解决 无用
    打赏 举报
  • dsxi70423 2017-09-26 15:11

    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;
    解决 无用
    打赏 举报

相关推荐 更多相似问题