Jump to content

array_rand function


phprookie72

Recommended Posts

hphrookie72, your requests are very vague and it makes it difficult for us to help you. As xyph stated if you don't want array_rand() to find specific items in an array - remove them. That is how you tell array_rand() not to return them. This kinda sounds like it could be a homework problem, so I'm not going to write any code for you. But, if you post some code you've written and need some help, we can push you in the right direction.

 

But, it all depends on HOW you want to limit the results from array_rand(). Do you know the exact values you want excluded? If so, look into array_diff(). IF you are wanting to exclude elements that 'contain' something in the value you're going to have to write a custom procedure to do that. Either a recursive process to continually get a value using array_rand() that matches your criteria OR preprocess the values in the array to remove ones that you don't want returned. Which one would depend on the size of the array and how many options would not apply.

Link to comment
https://forums.phpfreaks.com/topic/267707-array_rand-function/#findComment-1373290
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.