39 foreach ( $array as $elt ) {
40 $hashes[$elt] = md5( $elt . $separator . $key );
42 uasort( $array,
static function ( $a, $b ) use ( $hashes ) {
43 return strcmp( $hashes[$a], $hashes[$b] );
55 if ( !is_array( $weights ) || count( $weights ) == 0 ) {
59 $sum = array_sum( $weights );
61 # No loads on any of them
62 # In previous versions, this triggered an unweighted random selection,
63 # but this feature has been removed as of April 2006 to allow for strict
64 # separation of query groups.
67 $max = mt_getrandmax();
68 $rand = mt_rand( 0, $max ) / $max * $sum;
71 foreach ( $weights as $i => $w ) {
73 # Do not return keys if they have 0 weight.
74 # Note that the "all 0 weight" case is handed above
75 if ( $w > 0 && $sum >= $rand ) {
101 $comparisonCallback, $target
103 if ( $valueCount === 0 ) {
110 $mid = $min + ( ( $max - $min ) >> 1 );
111 $item = $valueCallback( $mid );
112 $comparison = $comparisonCallback( $target, $item );
113 if ( $comparison > 0 ) {
115 } elseif ( $comparison == 0 ) {
121 }
while ( $min < $max - 1 );
124 $item = $valueCallback( $min );
125 $comparison = $comparisonCallback( $target, $item );
126 if ( $comparison < 0 ) {
149 foreach ( $array1 as $key => $value ) {
150 if ( is_array( $value ) ) {
152 foreach ( $arrays as $array ) {
153 if ( isset( $array[$key] ) ) {
154 $args[] = $array[$key];
158 if ( count( $valueret ) ) {
159 $ret[$key] = $valueret;
162 foreach ( $arrays as $array ) {
163 if ( isset( $array[$key] ) && $array[$key] === $value ) {
199 $numInputs = count( $inputArrays );
200 if ( $numInputs === 0 ) {
205 foreach ( $inputArrays as &$inputArray ) {
206 if ( !count( $inputArray ) ) {
209 reset( $inputArray );
211 unset( $inputArray );
218 foreach ( $inputArrays as $inputArray ) {
219 $element[] = current( $inputArray );
221 $outputArrays[] = $element;
228 for ( $paramIndex = $numInputs - 1; $paramIndex >= 0; $paramIndex-- ) {
229 next( $inputArrays[$paramIndex] );
230 if ( key( $inputArrays[$paramIndex] ) ===
null ) {
231 reset( $inputArrays[$paramIndex] );
239 return $outputArrays;
244class_alias( ArrayUtils::class,
'ArrayUtils' );