$value ) { $bound_array_int_floor[ $i ] = array( 'floor' => (int) floor( $value ), 'fraction' => $value - floor( $value ), 'index' => $i, ); } return $bound_array_int_floor; } /** * Adjust the constrained array. * * @param array $bound_array_int - the array we're adjusting. * @param int $adjustment - how much we're adjusting the array. */ private static function adjust_constrained_array( &$bound_array_int, $adjustment ) { usort( $bound_array_int, array( 'self', 'cmp_desc_fraction' ) ); $start = 0; $end = $adjustment - 1; $length = count( $bound_array_int ); for ( $i = $start; $i <= $end; $i++ ) { $bound_array_int[ $i % $length ]['floor']++; } usort( $bound_array_int, array( 'self', 'cmp_asc_index' ) ); } /** * Compare fraction values of two arrays. * * @param array $a - the first array we're comparing. * @param array $b - the second array we're comparing. * * @return int */ private static function cmp_desc_fraction( $a, $b ) { if ( $a['fraction'] === $b['fraction'] ) { return 0; } return $a['fraction'] > $b['fraction'] ? -1 : 1; } /** * Compare index values of two arrays. * * @param array $a - the first array. * @param array $b - the second array. * * @return int */ private static function cmp_asc_index( $a, $b ) { if ( $a['index'] === $b['index'] ) { return 0; } return $a['index'] < $b['index'] ? -1 : 1; } }