note 71519 added to function.array-rand
| From: | FrederickLemassonakadjassperatgmail at osu1 dot php dot net | Date: | Mon, 04 Dec 2006 08:57:35 +0000 |
| Subject: | note 71519 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120260@lists.php.net to get a copy of this message | ||
To select a random Value (not a Key) from a Multi-Dimentionnal array I made a recursive function :
array_multi_rand()
the following exemple randomly selects an url from a multidimentionnal array :
<?
$Expos['Google']['Science']='news.google.fr/news?topic=t';
$Expos['Google']['Economie']='news.google.fr/news?topic=b';
$Expos['Google']['Sante']='news.google.fr/news?topic=m';
$Expos['Yahoo']='fr.news.yahoo.com';
$Expos['Events']['LogicielLibre']='agendadulibre.org';
$Expos['MyBlog']='www.kik-it.com';
function array_multi_rand($Zoo){
$Boo=array_rand($Zoo);
if(is_array($Zoo[$Boo])){
return array_multi_rand($Zoo[$Boo]);
}else{
return $Zoo[$Boo];
}
}
echo(array_multi_rand($Expos));
?>
----
Server IP: 195.221.21.36
Probable Submitter: 86.210.85.80
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/71519
Del: integrated -- https://master.php.net/note/delete/71519/integrated
Del: useless -- https://master.php.net/note/delete/71519/useless
Del: bad code -- https://master.php.net/note/delete/71519/bad+code
Del: spam -- https://master.php.net/note/delete/71519/spam
Del: non-english -- https://master.php.net/note/delete/71519/non-english
Del: in docs -- https://master.php.net/note/delete/71519/in+docs
Del: other reasons-- https://master.php.net/note/delete/71519
Reject -- https://master.php.net/note/reject/71519
Search -- https://master.php.net/manage/user-notes.php