Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

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