note 97625 deleted from function.array-rand by degeberg

From: Date: Thu, 29 Apr 2010 08:53:26 +0000
Subject: note 97625 deleted from function.array-rand by degeberg
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168777@lists.php.net to get a copy of this message
Note Submitter: dtbaker gmail Reason: integrated ---- For those who find that array_rand returns nothing, make sure the $num_req parameter isn't more than the number of elements in the array. <?php $foo = array(1,2); $result = array_rand($foo,6); // $result is nothing PHP5.2.4 ?> try this instead, if you don't have control over the number of elements in the input array. <?php $foo = array(1,2); $result = array_rand($foo,min(count($foo),6)); // $result contains 2 items. ?>

« previous php.notes (#168777) next »