gpt4 book ai didi

php - 压缩 PHP 查询

转载 作者:可可西里 更新时间:2023-11-01 00:06:05 25 4
gpt4 key购买 nike

我有一段代码,我怀疑它可以用更有效的方式编写,但我对某些 PHP 查询仍然有点生疏。

有没有更好的方法来编写以下查询:

<?php 
if(qtrans_getLanguage()=='en'): echo 'Latest News'; endif;
if(qtrans_getLanguage()=='it'): echo 'Ultime notizie'; endif;
if(qtrans_getLanguage()=='de'): echo 'Aktuelle Nachrichten'; endif;
if(qtrans_getLanguage()=='zh'): echo '最新消息'; endif;
if(qtrans_getLanguage()=='es'): echo 'Últimas noticias'; endif;
if(qtrans_getLanguage()=='fr'): echo 'Dernières nouvelles'; endif;
?>

最佳答案

使用 lookup table :

$table = array(
'en' => 'Latest News',
'it' => 'Ultime notizie',
....
);

echo $table[qtrans_getLanguage()];

关于php - 压缩 PHP 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13289866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com