PHP 变量如 $var['$var']
我目前正在制作一个带有相册的网站。该网站有两种语言:英语和荷兰语。所以我制作了如下语言文件:
$lang['hello'] = 'Hallo'; //Hallo is hello in dutch
对于相册,我尝试使用相同的原理,例如:
$lang['discription_001'] = 'photo of a house';
通过显示我制作的计数器的图像,现在我想在显示中使用相同的计数器,如下所示:
echo $lang['discription_'$counter]
和 $counter
是第一张照片的 001
。然而这不起作用,有人可以告诉我如何让它工作,或者任何其他方法来得到我想要的东西。
提前致谢,Thomas de
Zeeuw我是 PHP 新手,但是我通常学起来很快,所以做一些解释将不胜感激。
I'm current making a website with a photo album in it. The website in 2 languages, english and dutch. So I made language file like:
$lang['hello'] = 'Hallo'; //Hallo is hello in dutch
With the photo album I'm trying use the same principle like:
$lang['discription_001'] = 'photo of a house';
With showing the images I made a counter, now I want to use the same counter in the dispription like so:
echo $lang['discription_'$counter]
And $counter
being 001
for photo number one. However this does not work, Could someone tell how I could get this to work, or any other method to get what I want.
Thanks in advance, Thomas de Zeeuw
P.S. I'm new in PHP, however I normally pick up things quite fast, so make some explaintion would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您已经差不多完成了:
.
是 PHP 的连接运算符,用于组合字符串。You're almost there:
The
.
is PHP's concatenation operator, for combining strings.您只是忘记了 字符串连接运算符
.
来连接' discription_'
和$counter
的值:You just forgot the string concatenation operator
.
to concatenate'discription_'
and the value of$counter
:你有一个错字。
应该是
You have a typo.
Should be
您可以通过简单地修复代码来使其工作:
或者
You could get it to work by simple repairing your code:
or
$counter
是字符串吗?如果是这样,如果您修复了解析错误(您错过了串联运算符(.
)),您的示例应该可以正常工作。如果您向我们展示应用程序中的实际代码,那就更好了。
echo $ lang['描述_' . $counter];
Is
$counter
a string?? If so your example should work fine if you fix the parse error (You missed the concatenation operator (.
).It would be much better if you showed us actual code from your application.
echo $lang['discription_' . $counter];
由于您已经得到答案,因此您忘记了串联运算符,但在我看来更好的方法是使用多维数组。
As you have got answers already you forgot the concatenation operator, but better way in my mind would be to use multidimensional array.