Hello,
I have this array:
$arr = array("1-3"=>2,"4-8"=>2,"9-10"=>1,"11-20"=>0);
I would like to get a random key where the value is greater than 0. So in this example I won't get the "11-20" key
is that possible?
Thanks!
yes it is very possible and there is a few different ways you can accomplish this but the easiest it just calling the key.
but here is something a little more dynamic....
foreach($arr as $key => $value) { if(count($key) > 0) { echo $arr[$key]; } }
$positive = array_filter( $arr, create_function( '$var', 'return $var > 0;' ) ); $randKey = array_rand($positive);