beermantm Posted May 7, 2014 Report Posted May 7, 2014 I had to rethink this so many times, I was pulling out the hair in my head. Pulling out the hair that wasn't falling out naturally. If all PHP if this hard to figure out i might go back to css!! function randomNums() { $items = array(); $results = range(1,10); $i = 1; foreach($results as $result) { $result = mt_rand(1, 200); $items[] = $result; } $unique = array_unique($items, SORT_NUMERIC); $countem = count($unique); $unique_counted = $countem -5; $sum = array_slice($unique, $unique_counted); foreach ($sum as $key) { $output = $i++.' : '.$key.'<br>'; echo $output; } } randomNums(); What do ya think? Quote
beermantm Posted May 7, 2014 Author Report Posted May 7, 2014 function randomNums() { $results_to_gen = 1100; $low_range = 100000; $high_range = 200000; $trim_results_to= 1000; $items = array(); $results = range( 1, $results_to_gen); $i = 1; foreach($results as $result) { $result = mt_rand( $low_range, $high_range); $items[] = $result; } $unique = array_unique( $items, SORT_NUMERIC); $countem = count( $unique); $unique_counted = $countem -$trim_results_to; $sum = array_slice($unique, $unique_counted); foreach ($sum as $key) { $output = $i++.' : '.$key.'<br>'; echo $output; } } randomNums(); CLose to Final result. I think it came out nicely. Just need to swap out numbers for variables. Quote
LSW Posted May 8, 2014 Report Posted May 8, 2014 Only Hours? Well done, I have spent days on more than a few, even weeks occasionally. Quote
beermantm Posted May 8, 2014 Author Report Posted May 8, 2014 Only Hours? Well done, I have spent days on more than a few, even weeks occasionally. Putting it all together in my mind seems to be the difficult task. Mathematical functions seem easier for my brain to comprehend. I'm definitely learning more and at a faster rate at the moment. It will all come together soon I feel. Just rinse and repeat, rinse repeat. I could see where deadlines could become a problem. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.