http://ca.php.net/array_rand
When using array_rand, I am getting no values at all.
The array ($story) returns an array of 7 elements, when not passed through array_rand
I want to get 4 of the 7 elements randomly.
$story = function($getThese, 7)
$story = array_rand($story ,4);
When using array_rand, my var_dump shows this:
array(4) { [0]=> int(1) [1]=> int(4) [2]=> int(2) [3]=> int(3) }
I am using a multi-dimensional array.
Array Rand
Moderator: General Moderators
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Array Rand
Yes you are, you're getting a set of keys exactly as the manual says you will.$var wrote:http://ca.php.net/array_rand
When using array_rand, I am getting no values at all.
$story = function($getThese, 7)
$story = array_rand($story ,4);
But then you're overwriting the original array with this new array of keys.
Code: Select all
$storyKeys = array_rand($story ,4);
for each ($storyKeys as $storyKey) {
print_r($story[$storyKey]);
}