Simple Way to Calculate the Odds of Something Happening
Here is a quick way to express a chance of something happening.
This is an example in JavaScript that gives you a 1 in 3 chance of being true.
[true, false, false].sort(function(){ return Math.random() >= 0.5 ? 1 : -1 })[0]
Basically, we popu...
Written by Sean Behan on 11/27/2017
How to Get a Random Item from an Array in PHP
Use this snippet for grabbing a random item from an array in php
$fruits = ['apple', 'banana', 'carrot', 'date', 'elderberry'];
echo array_rand(array_flip($fruits));
// => 'banana'
PHP's `array_flip` makes the keys the values and the valu...
Written by Sean Behan on 11/10/2017