在数组中包含文件-PHP

时间:2018-10-14 09:39:11

标签: php

我在主要的php文件中有此代码,我想包含2个或更多的翻译文件

<?php
 $lang = array(
  'en' => array(
   include ('nav-translation/en.php');
   include ('home-translation/en.php');
  ),
  'lv' => array(
   include ('nav-translation/lv.php');
   include ('home-translation/lv.php');
  ),
 );
?>

并且有一个文件“ nav-translation / en.php”要包含到主文件中

<?php
 "home" => "Home",
 "about" => "About me",
 "blog" => "Blog",
?>

谢谢!

2 个答案:

答案 0 :(得分:0)

您可以使用

<?php
"home" => Translator::t('app','en',"Home"),
"about" => Translator::t('app','en',"About me"),
"blog" => Translator::t('app','en',"Blog"),
 ?>

答案 1 :(得分:0)

我认为您的数组应该是

 $lang = array(
  'en' => array(
   'nav-translation/en.php',
   'home-translation/en.php',
  ),
  'lv' => array(
   'nav-translation/lv.php',
   'home-translation/lv.php',
  ),
 );

,然后将nav-translation / en.php中的代码替换为

return array(
 "home" => "Home",
 "about" => "About me",
 "blog" => "Blog"
 );

要包含该文件,您应该编写

 $en_nav = include_once($lang["en"][0]);

并使用$ en_nav访问“ nav-translation / en.php”文件中的home,about,Blog键,因此,如果您需要交易Home键,则只需编写$ en_nav [“ home”]