In PHP, checking if a integer is negative and if it is then setting it to zero is easy, but I was looking for something shorter (and potentially faster) than:
if ($x < 0) $x = 0;
Well, this is a very quick check and reset, but there is a function max that does this too and it works with arrays too.
$x = max(0, $x); // $x will be set to 0 if it was less than 0
The max() function returns the number with the highest value of two specified numbers.
echo max(1, 3, 5, 6, 7); // 7 // If both an array and non-array are given, the array
echo max(array(2, 4, 5)); // 5
echo max(0, 'hello'); // 0
echo max('hello', 0); // hello
echo max(-1, 'hello'); // hello
// With multiple arrays, max compares from left to right
// so in our example: 2 == 2, but 4 < 5
$val = max(array(2, 4, 8), array(2, 5, 7)); // array(2, 5, 7)
// is always returned as it's seen as the largest
$val = max('string', array(2, 5, 7), 42); // array(2, 5, 7)
Since the first issue of Sprouter Weekly, we've been hunting down the newest, most exciting startups each week, and serving up four of them straight to your inbox. The thing about startups is that usually launch day is only the beginning. Here's a look
Twitter, Microsoft, Google and Engine recently presented at Criteo's Boom industry event. The day's tagline was, "Exploding the myths behind big data'. The aim was to place big data at the top of the list of priorities for companies and for them to m
Back home in the state of NJ and I want to recap the Affiliate Summit Central in Austin, Tx to everyone. First of all the show was intended to be small, I believe Shawn had a limitation of about 500 people to the event. I attended the show with some NJ af