我使用数组生成随机链接但无法根据数组随机选择添加一些值。 此文件是语言文件,其中包含不同语言的值
if($c2[2]=='en' || $c2[3]=='en'){$htmllang='en';$alt='Download';$text1='Wallpapers';$text2='HOLLYWOOD';}
elseif($c2[2]=='af' || $c2[3]=='af'){$htmllang='af';$alt='Aflaai';$text1='Wallpapers';$text2='HOLLYWOOD';}
else($c2[2]=='am' || $c2[3]=='am'){$htmllang='am';$alt='አውርድ';$text1='የግድግዳ';$text2='የሆሊዉድ';}
else($c2[2]=='ar' || $c2[3]=='ar'){$htmllang='ar';$alt='تحميل';$text1='خلفيات';$text2='هوليوود';}
这里是生成随机链接的代码
$extpo = array("af","sq","am","ar");
$random_keys=array_rand($extpo,3);
shuffle($extpo);
$randlink='<a href="http://somesitesss.com/some/'.$extpo[0].'/'.$city2.'">'.$extpo[0].'</a>';
$city2 is number .No issue here
它生成这样的链接
http://somesitesss.com/some/am/566556
我希望它在no之前包含$ alt值。像这样
http://somesitesss.com/some/am/አውርድ/566556
任何帮助都会很棒
答案 0 :(得分:0)
我不清楚你想要什么,所以我可能错了) 这是我认为应该是的代码:
$extpo = array("af","sq","am","ar");
// I don't think that you need $random_keys if you `shuffle` array
//$random_keys = array_rand($extpo,3);
shuffle($extpo);
$lang_key = $extpo[0];
// Okey, now `$lang_key` holds your lang code:
// Now I use your block of `if`s but I compare `$lang_key`
// As I don't know what is `$c2`
if ($lang_key == 'en'){
$htmllang='en';$alt='Download';$text1='Wallpapers';$text2='HOLLYWOOD';
} elseif ($lang_key == 'af') {
$htmllang='af';$alt='Aflaai';$text1='Wallpapers';$text2='HOLLYWOOD';
} elseif ($lang_key == 'am') {
$htmllang='am';$alt='አውርድ';$text1='የግድግዳ';$text2='የሆሊዉድ';
} elseif ($lang_key =='ar') {
$htmllang='ar';$alt='تحميل';$text1='خلفيات';$text2='هوليوود';
}
// now your `$alt` has a proper value according to `$lang_key`
// get a link:
$randlink='<a href="http://somesitesss.com/some/' . $lang_key . '/' . $alt . '/' . $city2 . '">'.$lang_key.'</a>';