51 foreach ( $array as $elt ) {
52 $hashes[$elt] = md5( $elt . $separator . $key );
54 uasort( $array,
static function ( $a, $b ) use (
$hashes ) {
67 if ( !is_array( $weights ) || count( $weights ) == 0 ) {
71 $sum = array_sum( $weights );
73 # No loads on any of them
74 # In previous versions, this triggered an unweighted random selection,
75 # but this feature has been removed as of April 2006 to allow for strict
76 # separation of query groups.
79 $max = mt_getrandmax();
80 $rand = mt_rand( 0, $max ) / $max * $sum;
83 foreach ( $weights as $i => $w ) {
85 # Do not return keys if they have 0 weight.
86 # Note that the "all 0 weight" case is handed above
87 if ( $w > 0 && $sum >= $rand ) {
114 $comparisonCallback, $target
116 if ( $valueCount === 0 ) {
123 $mid = $min + ( ( $max - $min ) >> 1 );
124 $item = $valueCallback( $mid );
125 $comparison = $comparisonCallback( $target, $item );
126 if ( $comparison > 0 ) {
128 } elseif ( $comparison == 0 ) {
134 }
while ( $min < $max - 1 );
137 $item = $valueCallback( $min );
138 $comparison = $comparisonCallback( $target, $item );
139 if ( $comparison < 0 ) {
162 foreach ( $array1 as $key => $value ) {
163 if ( is_array( $value ) ) {
165 foreach ( $arrays as $array ) {
166 if ( isset( $array[$key] ) ) {
167 $args[] = $array[$key];
171 if ( count( $valueret ) ) {
172 $ret[$key] = $valueret;
175 foreach ( $arrays as $array ) {
176 if ( isset( $array[$key] ) && $array[$key] === $value ) {
212 $numInputs = count( $inputArrays );
213 if ( $numInputs === 0 ) {
218 foreach ( $inputArrays as &$inputArray ) {
219 if ( !count( $inputArray ) ) {
222 reset( $inputArray );
224 unset( $inputArray );
231 foreach ( $inputArrays as $paramIndex => $inputArray ) {
232 $element[] = current( $inputArray );
234 $outputArrays[] = $element;
241 for ( $paramIndex = $numInputs - 1; $paramIndex >= 0; $paramIndex-- ) {
242 next( $inputArrays[$paramIndex] );
243 if ( key( $inputArrays[$paramIndex] ) ===
null ) {
244 reset( $inputArrays[$paramIndex] );
252 return $outputArrays;
A collection of static methods to play with arrays.
static arrayDiffAssocRecursive( $array1,... $arrays)
Do array_diff_assoc() on multi-dimensional arrays.
static consistentHashSort(&$array, $key, $separator="\000")
Sort the given array in a pseudo-random order which depends only on the given key and each element va...
static findLowerBound( $valueCallback, $valueCount, $comparisonCallback, $target)
Do a binary search, and return the index of the largest item that sorts less than or equal to the tar...
static pickRandom( $weights)
Given an array of non-normalised probabilities, this function will select an element and return the a...
static cartesianProduct(... $inputArrays)
Make an array consisting of every combination of the elements of the input arrays.