in reply to placing values into bins

If am doing histograms, I prefer to use arrays for binning. The general approach goes like this. First, in 1-d:

$histo[ ( $x - $x_min )/$x_bin_width ]++;
For example, if your $x_min == 100, and your $x_bin_width == 5, then for $x == 123.45 the line above would add one more count to $histo[4]. Note that there's an implicit int() around the contents of the []; the line above is equivalent to the slightly longer:
$histo[ int( ( $x - $x_min )/$x_bin_width ) ]++;
Also note that when the point lands at a boundary between bins, this scheme assigns it to the bin on the right. E.g. using the same parameters as before if $x is exactly 125, the code above would add 1 to $histo[5], not to $histo[4].

Now, for the 2-d case, it's basically the same idea:

$histo[ ( $x - $x_min )/$x_bin_width ][ ( $y - $y_min )/$y_bin_width ] +++;

the lowliest monk