Determing if an array has duplicate values in PHP

Recently, I had the need to determine whether an array had duplicate values in it. It didn't matter what the duplicate values were, or how many duplicates there were, either of which can be answered with array_count_values(), I just needed to know whether there were any at all; a boolean answer.

There are a lot of ways to approach it, but I found this to be the the most minimal:

$temp_array = array_unique($original_array);
$duplicates = sizeof($temp_array) != sizeof($original_array);

In a Rush? Install with Drush!

You know how to install Drupal the normal way, but there is a shortcut, if you have drush.

Drush provides a command (site-install) for downloading modules. Drupal, itself, is kept as a project in the modules section of Drupal. So, drush can download it, as well. Installing Drupal can be done with another drush command. Here is how to install Drupal, in 3 easy steps:

roundDown for php

It seems crazy that php doesn't have a native roundDown function.

It does have round(), which has various modes, but they only provide for rounding down if the starting value is < .5   In some cases, one must round up (the number of boxes needed to hold a quantity of items), but in some, it is necessary to always round down, in particular anywhere that a fraction of something makes no sense because the item is either whole or not.

There are numeric ways to accomplish this, such as:

$rounded_value = floor($value / 10^x) * 10^x