如何显示三个项目一个时间数组


How to show 3 items one time - array

$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>"); 
上面的

将这样做:

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

如何显示3个链接,例如雅虎,谷歌,必应

可以引用数组中相同的元素。一个函数应该足以满足这个

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