Php 如何一次显示3项-数组 $URL=数组(“http://google.com" ,"http://hotmail.com" ,"http://yahoo.com" ,"http://stackoverflow.com" ,"http://bing.com" ,"http://cnn.com" ); $text=数组(“谷歌”、“Hotmail”、“雅虎”、“Stackoverflow”、“Bing”、“CNN”); srand(time()); $random=(rand()%3); 回声(“”);
上述方法将实现这一点:Php 如何一次显示3项-数组 $URL=数组(“http://google.com" ,"http://hotmail.com" ,"http://yahoo.com" ,"http://stackoverflow.com" ,"http://bing.com" ,"http://cnn.com" ); $text=数组(“谷歌”、“Hotmail”、“雅虎”、“Stackoverflow”、“Bing”、“CNN”); srand(time()); $random=(rand()%3); 回声(“”);,php,Php,上述方法将实现这一点: $urls = array("http://google.com" ,"http://hotmail.com" ,"http://yahoo.com" ,"http://stackoverflow.com" ,"http://bing.com" ,"http://cnn.com" ); $text = array("Google" ,"Hotmail" ,"Yahoo" ,"Stackoverflow" ,"Bing" ,"CNN"); srand(
$urls = array("http://google.com" ,"http://hotmail.com" ,"http://yahoo.com" ,"http://stackoverflow.com" ,"http://bing.com" ,"http://cnn.com" );
$text = array("Google" ,"Hotmail" ,"Yahoo" ,"Stackoverflow" ,"Bing" ,"CNN");
srand(time());
$random = (rand()%3);
echo ("<a href = \"$urls[$random]\">$text[$random]</a>");
如何显示3个链接,例如Yahoo、Google、Bing您可以引用数组中的相同元素。一个函数应该就足够了
<a href="http://www.stackoverflow.com">Stackoverflow</a>
函数showLink(数组$url,数组$title,$position){
返回“”;
}
echo$showLink($url,$text,mt_rand(0,count($url)-1);
function showLink(Array $url, Array $title, $position) {
return '<a href = "' . $url[$position] . '">' . $title[$position] . '</a>';
}
echo $showLink($urls, $text, mt_rand(0, count($urls) -1);