我有一个数组$texts
,如下所示:
Array
(
[CAR_SINGULAR] => Array
(
[id] => 1
[translations] => Array
(
[de] => Auto
[en] => Car
)
)
[CAR_PLURAL] => Array
(
[id] => 2
[translations] => Array
(
[de] => Autos
[en] => cars
)
)
)
然后我有这段PHP代码,我希望为每个翻译国家/地区代码输出一个简单的h1
和input
类型文本。
foreach(array_keys($texts) as $text)
{
echo "<h1>". $text ."</h1>";
foreach($texts[$text] as $textData)
{
foreach(array_keys($textData) as $languageCode)
{
echo $languageCode .": <input type=\"text\" id=\"". $ID_OF_CODE_AND_TEXTID ."\" value=\"". $VALUE_OF_LANGUAGE_CODE ."\" /><br />";
}
}
}
结果应该是 -
<h1>CAR_SINGULAR</h1>
de: <input type="text" id="de_1" value="Auto" /><br />
en: <input type="text" id="en_1" value="car" />
<h1>CAR_PLURAL</h1>
de: <input type="text" id="de_2" value="Autos" /><br />
en: <input type="text" id="en_2" value="cars" />
但不知怎的,我太盲目了,无法将id
和value
添加到input
:-(
任何帮助将不胜感激:-)
答案 0 :(得分:1)
您必须添加html,但这是基本输出:
$texts = Array
(
"CAR_SINGULAR" => Array
(
"id" => 1,
"translations" => Array
(
"de" => "Auto",
"en" => "Car"
)
),
"CAR_PLURAL" => Array
(
"id" => 2,
"translations" => Array
(
"de" => "Autos",
"en" => "cars"
)
)
);
foreach($texts as $key => $subarr){
echo $key. "\n";
foreach($subarr["translations"] as $lang => $val){
echo $lang . ": " . $val . "\n";
}
echo "\n";
}
第一个数组的键是复数/单数 然后我循环内部子阵列并在“翻译”中输出它的值。