0

我有一段代码,我想在线获取结果

    $lang = $this->config->item('email');
    echo $lang['support_email'] ; die;

当我var_dump $lang的结果

array(11) {
  ["useragent"]=>
  string(11) "CodeIgniter"
  ["mailpath"]=>
  string(17) "/usr/bin/sendmail"
  ["protocol"]=>
  string(4) "mail"
  ["smtp_host"]=>
  string(9) "localhost"
  ["smtp_user"]=>
  string(0) ""
  ["smtp_pass"]=>
  string(0) ""
  ["smtp_port"]=>
  string(2) "25"
  ["system_email"]=>
  string(21) "noreply@elephanti.com"
  ["help_email"]=>
  string(18) "help@elephanti.com"
  ["inquiries_email"]=>
  string(23) "inquiries@elephanti.com"
  ["support_email"]=>
  string(21) "support@elephanti.com"
}

我试过

回声$this->config->item('email')['support_email']

echo echo `$this->config->item('email')->support_email 

请帮忙.............

4

4 回答 4

3
$lang = $this->config->item('email', 'support_email');

从文档:

http://codeigniter.com/user_guide/libraries/config.html

// Retrieve a config item named site_name contained within the blog_settings 数组`

$site_name = $this->config->item('site_name', 'blog_settings');

于 2012-05-07T10:40:41.467 回答
1

你只能echo $this->config->item('email')['support_email']在 PHP 5.4+ 中做

否则你能做的最好的就是:

$lang=$this->config->item('email');echo $lang['support_email'];exit;

或者编写一个自定义函数来为你做这件事。

但是然后问自己,为什么必须在一行中执行此操作……?

于 2012-05-07T10:37:41.223 回答
1

echo $this->config->item('email')['support_email']

这实际上适用于 PHP > 5.4。在旧版本中,不可能在一个语句中完成,因此您必须将数组存储在单独的局部变量中。您可以创建一个函数来检索这样的值:

 <?php
 function array_get( array $array, $index ) {
    return isset( $array[$index] ) ? $array[$index] : false;
 }

 echo array_get( $this->config->item( 'email' ), 'support_email' );

但这真的没用。您想在一行中执行此操作的任何特殊原因?

于 2012-05-07T10:40:23.887 回答
0

尝试:

foreach($lang as $key=>$val)
{
  if($key == "support_email")
  {
    echo $val;
  }
}
于 2012-05-07T10:39:35.990 回答