note 87051 added to function.array-rand
| From: | vista_ at live dot se | Date: | Mon, 17 Nov 2008 09:41:42 +0000 |
| Subject: | note 87051 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146619@lists.php.net to get a copy of this message | ||
Do you think it is ugly to output $array[array_rand($array)] ? Use this!
<?php
if(!function_exists('array_rand_'))
{
function array_rand_($array, $limit = 1)
{
return $array[array_rand($array, $limit)];
}
}
?>
Before: <?php echo $array[array_rand($array)]; ?>
After: <?php echo array_rand_($array); ?>
If you don't want to create a variable, this is great fun. You can write <?php echo
array_rand_(array(1,2,3)); ?> :)
----
Server IP: 212.63.193.10
Probable Submitter: 85.228.34.71
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- https://master.php.net/note/edit/87051
Del: integrated -- https://master.php.net/note/delete/87051/integrated
Del: useless -- https://master.php.net/note/delete/87051/useless
Del: bad code -- https://master.php.net/note/delete/87051/bad+code
Del: spam -- https://master.php.net/note/delete/87051/spam
Del: non-english -- https://master.php.net/note/delete/87051/non-english
Del: in docs -- https://master.php.net/note/delete/87051/in+docs
Del: other reasons-- https://master.php.net/note/delete/87051
Reject -- https://master.php.net/note/reject/87051
Search -- https://master.php.net/manage/user-notes.php