Split array into groups with nearly equal number of elements
@param array $arr
@param int $num_groups
@param bool $strict_group_count
@param bool $backload
@return array
343159
public static function apportion($arr, $num_groups = 2, $strict_group_count = false, $backload = false)
    {
        if (!self::iterable($arr)) {
            return array();
        }
        
        if ($backload) {
            $arr = array_reverse($arr, true);
        }
        
        $apportioned = array();
        $per_group = ceil(count($arr) / $num_groups);
        if ($strict_group_count) {
            $apportioned = array_chunk($arr, $per_group, true);
        } else {
            $shortage = ($per_group * $num_groups) - count($arr);
            if ($shortage > 1) {
                $keys = array_keys($arr);
                $first_keys = array_splice($keys, 0, $per_group);
                $first_group = array_splice($arr, 0, $per_group);
                $first_group = array_combine($first_keys, $first_group);
                $arr = array_combine($keys, $arr);
                $remainders = self::apportion($arr, $num_groups - 1);
                $apportioned = array_merge(array($first_group), $remainders);
            } else {
                $apportioned = array_chunk($arr, $per_group, true);
            }
        }

        if ($backload) {
            foreach ($apportioned as &$group) {
                $group = array_reverse($group, true);
            }
            $apportioned = array_reverse($apportioned, true);
        }
        return $apportioned;
    }
1145385
public static function array_checksum_recursive($arr) {

        $checksum = ''; // Init checksum

        // Check we are going to process one array always, objects must be cast before
        if (!is_array($arr)) {
            throw new backup_helper_exception('array_expected');
        }
        foreach ($arr as $key => $value) {
            if ($value instanceof checksumable) {
                $checksum = md5($checksum . '-' . $key . '-' . $value->calculate_checksum());
            } else if (is_object($value)) {
                $checksum = md5($checksum . '-' . $key . '-' . self::array_checksum_recursive((array)$value));
            } else if (is_array($value)) {
                $checksum = md5($checksum . '-' . $key . '-' . self::array_checksum_recursive($value));
            } else {
                $checksum = md5($checksum . '-' . $key . '-' . $value);
            }
        }
        return $checksum;
    }
1369590
public static function array_pop_rand(array &$arr) {
		$length = \count($arr);

		if (! $length) {
			return false;
		}

		// Nothing random about an array with one thing.
		if (1 === $length) {
			return static::array_pop_top($arr);
		}

		$keys = \array_keys($arr);
		$index = static::random_int(0, $length - 1);

		return $arr[$keys[$index]];
	}
909066
function( arr, results ) {
		var ret = results || [];

		if ( arr != null ) {
			if ( isArraylike( Object(arr) ) ) {
				jQuery.merge( ret,
					typeof arr === "string" ?
					[ arr ] : arr
				);
			} else {
				core_push.call( ret, arr );
			}
		}

		return ret;
	}
188724
static function toArray($kvs, $strict=false)
    {
        $lines = explode("\n", $kvs);

        $last = array_pop($lines);
        if ($last !== '') {
            array_push($lines, $last);
            if ($strict) {
                return false;
            }
        }

        $values = array();

        for ($lineno = 0; $lineno < count($lines); $lineno++) {
            $line = $lines[$lineno];
            $kv = explode(':', $line, 2);
            if (count($kv) != 2) {
                if ($strict) {
                    return false;
                }
                continue;
            }

            $key = $kv[0];
            $tkey = trim($key);
            if ($tkey != $key) {
                if ($strict) {
                    return false;
                }
            }

            $value = $kv[1];
            $tval = trim($value);
            if ($tval != $value) {
                if ($strict) {
                    return false;
                }
            }

            $values[$tkey] = $tval;
        }

        return $values;
    }
1329140
public function split($numberOfGroups)
    {
        if ($this->isEmpty()) {
            return new static;
        }

        $groups = new static;

        $groupSize = floor($this->count() / $numberOfGroups);

        $remain = $this->count() % $numberOfGroups;

        $start = 0;

        for ($i = 0; $i < $numberOfGroups; $i++) {
            $size = $groupSize;

            if ($i < $remain) {
                $size++;
            }

            if ($size) {
                $groups->push(new static(\array_slice($this->items, $start, $size)));

                $start += $size;
            }
        }

        return $groups;
    }
357227
function loadArrayOptGroups($arr, $values=null)
    {
        if (!is_array($arr)) {
            return self::raiseError('Argument 1 of HTML_Select::loadArrayOptGroups is not a valid array');
        }
        if (isset($values)) {
            $this->setSelected($values);
        }
        foreach ($arr as $key => $val) {
            // Warning: new API since release 2.3
            $this->addOptGroup($key, $val);
        }
        return true;
    }
116778
public static function arrMergeAll(array &$arr, $arr2)
    {
        if (is_array($arr2)) {
            foreach ($arr2 as $key => $val) {
                $arr[$key] = $val;
            }
        } else {
            $arr[] = $arr2;
        }

        return $arr;
    }
1192060
public static function array_next_element($arr, $nested_key, $iteration = 1)
    {
        foreach ($arr as $key => $v) {
            current($arr);

            if ($key == $nested_key) {
                for ($i = 0; $i < $iteration; $i++) {
                    $return = next($arr);
                }

                if (!empty($return)) {
                    return $return;
                } else {
                    return false;
                }
            }

            next($arr);
        }

        return false;
    }
236398
function (arr) {
        var result = true;
        arr.forEach(function (elem) {
            if (!(typeof elem === 'string' || typeof elem === 'number')) {
                result = false;
            }
        });

        return result;
    }
1072772
function(arr) {
      var n = [], l=arr.length,i;
      for(i = 0 ; i < l ; i++) {
         if( !lang.isNull(arr[i]) && !lang.isUndefined(arr[i]) ) {
            n.push(arr[i]);
         }
      }
      return n;
   }
190833
function setGroups( $groupArray )
    {
        $resultArray = array();
        // Check for readOnly
        foreach ( $groupArray as $blockName => $blockVariables )
        {
            foreach ( $blockVariables as $variableName => $variableValue )
            {
                if ( !$this->isSettingReadOnly( $this->FileName, $blockName, $variableName ) )
                    continue;
                $resultArray[$blockName][$variableName] = $variableValue;
            }
        }
        $this->BlockValues = $resultArray;
    }
522978
public static function array_type(&$arr=null) {
		if (! \is_array($arr) || ! \count($arr)) {
			return false;
		}

		$keys = \array_keys($arr);
		if (\range(0, \count($keys) - 1) === $keys) {
			return 'sequential';
		}
		elseif (\count($keys) === \count(\array_filter($keys, 'is_numeric'))) {
			return 'indexed';
		}
		else {
			return 'associative';
		}
	}
348995
private static function fromArray($arr, &$result = [], $limit = false, $offset = 1)
    {
        if (is_null($arr)) {
            return $arr;
        }
        if (false === $limit) {
            $limit = strlen($arr) - 1;
            $result = [];
        }
        if ('{}' != $arr) {
            do {
                if ('{' != $arr{$offset}) {
                    preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $arr, $match, 0, $offset);
                    $offset += strlen($match[0]);
                    $result[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
                    if ('},' == $match[3]) {
                        return $offset;
                    }
                } else {
                    $innerResult = [];
                    $offset = self::fromArray($arr, $innerResult, $limit, $offset + 1);

                    $result[] = $innerResult;
                }
            } while ($limit > $offset);
        }

        return $result;
    }
462279
function mltNum(arr, num) {
  arr.forEach((singlet, i) => {
    arr[i] *= num; 
  });
}
1135168
public static function equal ($array, $strict = false)
		{
			if (is_array($array))
			{
				if ($strict)
				{
					$data = array_values($array);
					for ($i = 0; $i < count($data); $i++)
					{
						for ($j = $i + 1; $j < count($data); $j++)
							if ($data[ $i ] !== $data[ $j ])
								return false;
					}

					return true;
				}
				else
					return ( count(array_unique($array)) === 1 );
			}
			else
				return null;
		}
204199
public static function binaryFormat($val_arr,$format_str)
    {
        if (!is_array($val_arr))
        {
            return false;
        }
        $param = array_merge( array($format_str) ,$val_arr);
        $pkt = call_user_func_array('pack',$param);
        return $pkt;
    }