2016-08-14 65 views
-1
$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项一次 - 阵列

<a href="http://www.stackoverflow.com">Stackoverflow</a> 

如何显示例如雅虎,谷歌3个环节,兵

回答

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);