51 foreach ( $array as $elt ) {
52 $hashes[$elt] = md5( $elt . $separator . $key );
54 uasort( $array,
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 ) {
113 $comparisonCallback, $target
115 if ( $valueCount === 0 ) {
122 $mid = $min + ( ( $max - $min ) >> 1 );
123 $item = call_user_func( $valueCallback, $mid );
124 $comparison = call_user_func( $comparisonCallback, $target, $item );
125 if ( $comparison > 0 ) {
127 } elseif ( $comparison == 0 ) {
133 }
while ( $min < $max - 1 );
136 $item = call_user_func( $valueCallback, $min );
137 $comparison = call_user_func( $comparisonCallback, $target, $item );
138 if ( $comparison < 0 ) {
159 $arrays = func_get_args();
160 array_shift( $arrays );
163 foreach ( $array1 as $key =>
$value ) {
164 if ( is_array(
$value ) ) {
166 foreach ( $arrays as $array ) {
167 if ( isset( $array[$key] ) ) {
168 $args[] = $array[$key];
171 $valueret = call_user_func_array( __METHOD__,
$args );
172 if ( count( $valueret ) ) {
173 $ret[$key] = $valueret;
176 foreach ( $arrays as $array ) {
177 if ( isset( $array[$key] ) && $array[$key] ===
$value ) {
213 $numInputs = count( $inputArrays );
214 if ( $numInputs === 0 ) {
219 foreach ( $inputArrays as &$inputArray ) {
220 if ( !count( $inputArray ) ) {
223 reset( $inputArray );
225 unset( $inputArray );
232 foreach ( $inputArrays as $paramIndex => $inputArray ) {
233 $element[] = current( $inputArray );
235 $outputArrays[] = $element;
242 for ( $paramIndex = $numInputs - 1; $paramIndex >= 0; $paramIndex-- ) {
243 next( $inputArrays[$paramIndex] );
244 if (
key( $inputArrays[$paramIndex] ) ===
null ) {
245 reset( $inputArrays[$paramIndex] );
253 return $outputArrays;
A collection of static methods to play with 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 arrayDiffAssocRecursive( $array1)
Do array_diff_assoc() on multi-dimensional arrays.
static cartesianProduct(... $inputArrays)
Make an array consisting of every combination of the elements of the input arrays.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret