2016-08-14 1 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>"); 

Above wird dies tun:Wie man in 3 Einzelteile zeigen - Array

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

Wie 3 Links zum Beispiel Yahoo, um zu zeigen, Google, Bing

Antwort

1

Sie können das gleiche Element der Referenz das Array. Dazu sollte eine Funktion

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