2

我想了解如何将小字符串存储在数组中并正确输出。在这种情况下,我想在顶部的数组中设置一个两个字母的语言代码,然后稍后以该语言输出一个字符串。

我真的很感谢你的帮助。

我制作的以下代码不起作用,但我正在寻找这样的东西:

<?php

// Set the language
$settings = array(
  Language => "en"
);

// Set the strings
$locales = array(
  Installed => array("en", "da"),
  TheString => array("Dog", "Hund")
);

// Do some magic
$lang = $settings["Language"][0];

// Output Dog (or Hund if the language is "da")
echo $lang["TheString"];

?>
4

1 回答 1

4
$settings = array( 'lanaguage' => 'en');

$locales = array( 
    'en' => array(
        'dog' => 'dog'
    ),
    'da' => array(
        'dog' => 'hund'
    )
);

// You don't need this, but you can get it like so:
$installed_languages = array_keys( $locales); 

echo $locales[ $settings['language'] ]['dog'];

这将输出dogif $settings['language']isenhundif it is da

于 2012-06-26T00:39:19.780 回答