@param array $aArray
@param array $aBaseCol
@param string $sNameNewCol
@param string $sColNameToForceZero

@return array
772485
public static function calculateGamePoints($aArray, $aBaseCol, $sNameNewCol, $sColNameToForceZero = '')
    {
        if (empty($aArray)) {
            return $aArray;
        }

        $nameRankCol  = array_shift($aBaseCol);
        $nameEqualCol = array_shift($aBaseCol);

        $nbPlayers     = count($aArray);
        $nbFirstEquals = 1;
        foreach ($aArray as $aRank) {
            if ($aRank[$nameRankCol] == 1) {
                $nbFirstEquals = $aRank[$nameEqualCol];
                break;
            }
        }

        //Get formula to first into ranking
        $a = (-1 / (100 + $nbPlayers - $nbFirstEquals)) + 0.0101 + (log($nbPlayers) / 15000);
        $b = (atan($nbPlayers - 25) + M_PI_2) * (25000 * ($nbPlayers - 25)) / (200 * M_PI);
        $f = ceil((10400000 * $a + $b) / ($nbFirstEquals ** (6 / 5)));

        $aF    = [];
        $aF[1] = $f;
        for ($i = 2; $i <= $nbPlayers; ++$i) {
            $g      = min(0.99, log($i) / (log(71428.6 * $i + 857142.8)) + 0.7);
            $aF[$i] = $aF[$i - 1] * $g;
        }

        for ($i = 0; $i < $nbPlayers; ++$i) {
            //If a column name to force the 0 value is defined, force the 0 value of the new column if the related
            //column value is 0
            if ($sColNameToForceZero !== '' &&
                isset($aArray[$i][$sColNameToForceZero]) &&
                $aArray[$i][$sColNameToForceZero] == 0
            ) {
                $aArray[$i][$sNameNewCol] = 0;
                continue;
            }

            //If firsts
            if ($aArray[$i][$nameRankCol] == 1) {
                $aArray[$i][$sNameNewCol] = (int)round($f, 0);
                continue;
            }
            //If non equals
            if ($aArray[$i][$nameEqualCol] == 1) {
                $aArray[$i][$sNameNewCol] = (int)round($aF[$aArray[$i][$nameRankCol]], 0);
                continue;
            }
            //If equals (do average of players gives if they weren't tied)
            $aTiedValues = [];
            for ($j = 0; $j < $aArray[$i][$nameEqualCol]; ++$j) {
                $aTiedValues[] = $aF[$aArray[$i][$nameRankCol] + $j];
            }
            $value = round(array_sum($aTiedValues) / count($aTiedValues), 0);
            for ($j = $i, $nb = $i + count($aTiedValues); $j < $nb; ++$j) {
                $aArray[$i][$sNameNewCol] = (int)$value;
                $i++;
            }
            $i--;
        }

        return $aArray;
    }
309085
private function createClientsNode() : ArrayNodeDefinition
    {
        $builder = new TreeBuilder('clients');

        /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node */
        if (method_exists($builder, 'getRootNode')) {
            $node = $builder->getRootNode();
        } else {
            // BC layer for symfony/config 4.1 and older
            $node = $builder->root('clients');
        }

        /** @var \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeChildren */
        $nodeChildren = $node->useAttributeAsKey('name')
            ->prototype('array')
                ->children();

        $nodeChildren->scalarNode('class')->defaultValue('%eight_points_guzzle.http_client.class%')->end()
                    ->scalarNode('base_url')
                        ->defaultValue(null)
                        ->validate()
                            ->ifTrue(function ($v) {
                                return !is_string($v);
                            })
                            ->thenInvalid('base_url can be: string')
                        ->end()
                    ->end()
                    ->booleanNode('lazy')->defaultValue(false)->end()
                    ->scalarNode('handler')
                        ->defaultValue(null)
                        ->validate()
                            ->ifTrue(function ($v) {
                                return $v !== null && (!is_string($v) || !class_exists($v));
                            })
                            ->thenInvalid('handler must be a valid FQCN for a loaded class')
                        ->end()
                    ->end()
                    ->arrayNode('options')
                        ->validate()
                            ->ifTrue(function ($options) {
                                return count($options['form_params']) && count($options['multipart']);
                            })
                            ->thenInvalid('You cannot use form_params and multipart at the same time.')
                        ->end()
                        ->children()
                            ->arrayNode('headers')
                                ->useAttributeAsKey('name')
                                ->normalizeKeys(false)
                                ->prototype('scalar')->end()
                            ->end()
                            ->variableNode('allow_redirects')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_array($v) && !is_bool($v);
                                    })
                                    ->thenInvalid('allow_redirects can be: bool or array')
                                ->end()
                            ->end()
                            ->variableNode('auth')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_array($v) && !is_string($v);
                                    })
                                    ->thenInvalid('auth can be: string or array')
                                ->end()
                            ->end()
                            ->variableNode('query')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v) && !is_array($v);
                                    })
                                    ->thenInvalid('query can be: string or array')
                                ->end()
                            ->end()
                            ->arrayNode('curl')
                                ->beforeNormalization()
                                    ->ifArray()
                                        ->then(function (array $curlOptions) {
                                            $result = [];

                                            foreach ($curlOptions as $key => $value) {
                                                $optionName = 'CURLOPT_' . strtoupper($key);

                                                if (!defined($optionName)) {
                                                    throw new InvalidConfigurationException(sprintf(
                                                        'Invalid curl option in eight_points_guzzle: %s. ' .
                                                        'Ex: use sslversion for CURLOPT_SSLVERSION option. ' . PHP_EOL .
                                                        'See all available options: http://php.net/manual/en/function.curl-setopt.php',
                                                        $key
                                                    ));
                                                }

                                                $result[constant($optionName)] = $value;
                                            }

                                            return $result;
                                        })
                                    ->end()
                                    ->prototype('scalar')
                                ->end()
                            ->end()
                            ->variableNode('cert')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v) && (!is_array($v) || count($v) !== 2);
                                    })
                                    ->thenInvalid('cert can be: string or array with two entries (path and password)')
                                ->end()
                            ->end()
                            ->scalarNode('connect_timeout')
                                ->beforeNormalization()
                                    ->always(function ($v) {
                                        return is_numeric($v) ? (float) $v : $v;
                                    })
                                ->end()
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0);
                                    })
                                    ->thenInvalid('connect_timeout can be: float')
                                ->end()
                            ->end()
                            ->booleanNode('debug')->end()
                            ->variableNode('decode_content')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v) && !is_bool($v);
                                    })
                                    ->thenInvalid('decode_content can be: bool or string (gzip, compress, deflate, etc...)')
                                ->end()
                            ->end()
                            ->floatNode('delay')->end()
                            ->arrayNode('form_params')
                                ->useAttributeAsKey('name')
                                ->prototype('variable')->end()
                            ->end()
                            ->arrayNode('multipart')
                                ->prototype('variable')->end()
                            ->end()
                            ->scalarNode('sink')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v);
                                    })
                                    ->thenInvalid('sink can be: string')
                                ->end()
                            ->end()
                            ->booleanNode('http_errors')->end()
                            ->variableNode('expect')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_bool($v) && !is_int($v);
                                    })
                                    ->thenInvalid('expect can be: bool or int')
                                ->end()
                            ->end()
                            ->variableNode('ssl_key')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v) && (!is_array($v) || count($v) !== 2);
                                    })
                                    ->thenInvalid('ssl_key can be: string or array with two entries (path and password)')
                                ->end()
                            ->end()
                            ->booleanNode('stream')->end()
                            ->booleanNode('synchronous')->end()
                            ->scalarNode('read_timeout')
                                ->beforeNormalization()
                                    ->always(function ($v) {
                                        return is_numeric($v) ? (float) $v : $v;
                                    })
                                ->end()
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0);
                                    })
                                    ->thenInvalid('read_timeout can be: float')
                                ->end()
                            ->end()
                            ->scalarNode('timeout')
                                ->beforeNormalization()
                                    ->always(function ($v) {
                                        return is_numeric($v) ? (float) $v : $v;
                                    })
                                ->end()
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0);
                                    })
                                    ->thenInvalid('timeout can be: float')
                                ->end()
                            ->end()
                            ->variableNode('verify')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_bool($v) && !is_string($v);
                                    })
                                    ->thenInvalid('verify can be: bool or string')
                                ->end()
                            ->end()
                            ->booleanNode('cookies')->end()
                            ->arrayNode('proxy')
                                ->beforeNormalization()
                                ->ifString()
                                    ->then(function($v) { return ['http'=> $v]; })
                                ->end()
                                ->validate()
                                    ->always(function($v) {
                                        if (empty($v['no'])) {
                                            unset($v['no']);
                                        }
                                        return $v;
                                    })
                                ->end()
                                ->children()
                                    ->scalarNode('http')->end()
                                    ->scalarNode('https')->end()
                                    ->arrayNode('no')
                                        ->prototype('scalar')->end()
                                    ->end()
                                ->end()
                            ->end()
                            ->scalarNode('version')
                                ->validate()
                                    ->ifTrue(function ($v) {
                                        return !is_string($v) && !is_float($v);
                                    })
                                    ->thenInvalid('version can be: string or float')
                                ->end()
                            ->end()
                        ->end()
                    ->end();

        $pluginsNode = $nodeChildren->arrayNode('plugin')->addDefaultsIfNotSet();

        foreach ($this->plugins as $plugin) {
            $pluginNode = new ArrayNodeDefinition($plugin->getPluginName());

            $plugin->addConfiguration($pluginNode);

            $pluginsNode->children()->append($pluginNode);
        }

        return $node;
    }
444785
private function sManageDynamicFilters($filterArray = null, $tableToApplyFilterTo = '')
    {
        if (is_null($filterArray)) {
            return '';
        }
        $fltr = [];
        unset($filterArray['LIMIT']);
        foreach ($filterArray as $key => $value) {
            $fltr[] = '`' . $tableToApplyFilterTo . '`.`' . $key . '` ' . $this->sGlueFilterValIntoWhereStr($value);
        }
        return $this->sManageDynamicFiltersFinal($fltr);
    }
1287177
function addArray($arr, &$n, $name=""){
		foreach ($arr as $key => $val){
			if (is_int($key)){
				if (strlen($name)>1){
					$newKey = blib_grammar::singular($name); //substr($name, 0, strlen($name)-1);
				}else{
					$newKey="item";
				}
			}else{
				$newKey = $key;
			}

			$node = $this->doc->createElement($newKey);
			if (is_array($val)){
				$this->addArray($arr[$key], $node, $key);
			}else{
				$nodeText = $this->doc->createTextNode($val);
				$node->appendChild($nodeText);
			}
			$n->appendChild($node);
		}
	}
33
public function getInArray($name, array $array)
    {
        $value = $this->get($name);
        return in_array($value, $array) ? $value : $array[key($array)];
    }
660467
protected function extractDtoName($dto, $isArray = false)
    {
        $dto = explode('\\', $dto);
        $modelDto = array_pop($dto) . "Dto";
        if ($isArray) {
            $modelDto .= "List";
        }

        return $modelDto;
    }
977358
protected function setArrayToSelect($aElements, $sDefaultValue, $selectName, $featArray = null)
    {
        if (!is_array($aElements)) {
            return '';
        }
        if (isset($featArray['readonly'])) {
            $inputFeatures = [
                'name'     => $selectName,
                'id'       => $this->buildSelectId($selectName, $featArray),
                'readonly' => 'readonly',
                'class'    => 'input_readonly',
                'value'    => $sDefaultValue,
            ];
            return $this->setStringIntoShortTag('input', $inputFeatures) . $aElements[$sDefaultValue];
        }
        return $this->setArrayToSelectNotReadOnly($aElements, $sDefaultValue, $selectName, $featArray);
    }
282799
public static function column($array, $name, $keepKeys = true)
    {
        $result = [];
        if ($keepKeys) {
            foreach ($array as $k => $element) {
                $result[$k] = static::get($element, $name);
            }
        } else {
            foreach ($array as $element) {
                $result[] = static::get($element, $name);
            }
        }
        return $result;
    }
791678
public static function arrayUniqueMulti(array $aArray)
    {
        // Unique Array for return
        $aArrayRewrite = [];

        // Array with the md5 hashes
        $aArrayHashes = [];

        foreach ($aArray as $key => $item) {

            // Serialize the current element and create a md5 hash
            $hash = md5(serialize($item));

            /**
             * If the md5 didn't come up yet, add the element to to arrayRewrite,
             * otherwise drop it
             */

            if (!isset($aArrayHashes[$hash])) {

                // Save the current element hash
                $aArrayHashes[$hash] = $hash;

                // Add element to the unique Array
                $aArrayRewrite[$key] = $item;
            }
        }

        unset($aArrayHashes);
        unset($key);
        unset($item);
        unset($hash);

        return $aArrayRewrite;
    }
1130202
protected function prepareArguments(bool $asArray = true)
    {
        $arguments = array_merge(
            [$this->getBaseOptions()],
            $this->getOptions(),
            $this->getParameters()
        );

        if (false === $asArray) {
            $arguments = implode(' ', $arguments);
        }

        return $arguments;
    }
261326
public function diffArrays( array $arrayOne, array $arrayTwo ): array {
		$notInTwo = [];

		foreach ( $arrayOne as $element ) {
			$valueOffset = $this->arraySearch( $element, $arrayTwo );

			if ( $valueOffset === false ) {
				$notInTwo[] = $element;
				continue;
			}

			unset( $arrayTwo[$valueOffset] );
		}

		return $notInTwo;
	}
1132144
public function getAssociatedByName($names)
    {
        $return = [];

        $table = $this->_table();
        foreach ($names as $association) {
            $associationClass = $table->associations()->get($association);
            if (!$associationClass) {
                throw new RuntimeException(sprintf(
                    'Table "%s" is not associated with "%s"',
                    get_class($table),
                    $association
                ));
            }
            $return[$associationClass->getName()] = $associationClass;
        }

        return $return;
    }
1234264
protected function _getVisibleColNames()
    {
        $aColNames = $this->_getColNames();
        $aUserCols = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aCols');
        $aVisibleCols = [];

        // user defined some cols to load ?
        if (is_array($aUserCols)) {
            foreach ($aUserCols as $iKey => $sCol) {
                $iCol = ( int ) str_replace('_', '', $sCol);
                if (isset($aColNames[$iCol]) && !$aColNames[$iCol][4]) {
                    $aVisibleCols[$iCol] = $aColNames[$iCol];
                }
            }
        }

        // no user defined valid cols ? setting defauls ..
        if (!count($aVisibleCols)) {
            foreach ($aColNames as $sName => $aCol) {
                // visible ?
                if ($aCol[1] && !$aColNames[$sName][4]) {
                    $aVisibleCols[$sName] = $aCol;
                }
            }
        }

        return $aVisibleCols;
    }
972351
function _getIndexesInArray(attrs, attr) {
    var res = [];

    for (var i = 0; i < attrs.length; i++) {
        if (attrs[i].name === attr) res.push(i);
    }

    return res;
}
709922
public function beanToArray(array $fields_name, \SugarBean $bean, $pretty = false, $lang = 'en_us')
    {
        $module_definition = null;
        if ($pretty) {
            $module_definition = $this->getModuleFields($bean->module_name, $lang);
        }
        $fields = array();
        foreach ($fields_name as $field_name) {
            $key = $field_name;
            $value = $bean->$field_name;
            if (!is_null($module_definition)) {
                list($key, $value) = $this->applyLabelsToField($module_definition, $key, $value);
            }
            $fields[$key] = $value;
        }
        return $fields;
    }
971480
public function read( $asArray = NULL )
	{
		$json	= FS_File_Reader::load( $this->filePath );
		$data	= json_decode( $json, $asArray );
		if( json_last_error() !== JSON_ERROR_NONE ){
			$message	= 'Decoding JSON failed (%s): %s';
			$message	= vsprintf( $message, array(
				ADT_Constant::getKeyByValue( 'JSON_ERROR_', json_last_error() ),
				json_last_error_msg()
			) );
			throw new RuntimeException( $message, json_last_error() );
		}
		return $data;
	}
713768
public function to_array($custom = false, $recurse = false, $eav = false)
	{
		// storage for the result
		$array = array();

		// reset the references array on first call
		$recurse or static::$to_array_references = array(get_class($this));

		// make sure all data is scalar or array
		if ($custom)
		{
			foreach ($this->_custom_data as $key => $val)
			{
				if (is_object($val))
				{
					if (method_exists($val, '__toString'))
					{
						$val = (string) $val;
					}
					else
					{
						$val = get_object_vars($val);
					}
				}
				$array[$key] = $val;
			}
		}

		// make sure all data is scalar or array
		foreach ($this->_data as $key => $val)
		{
			if (is_object($val))
			{
				if (method_exists($val, '__toString'))
				{
					$val = (string) $val;
				}
				else
				{
					$val = get_object_vars($val);
				}
			}
			$array[$key] = $val;
		}

		// convert relations
		foreach ($this->_data_relations as $name => $rel)
		{
			if (is_array($rel))
			{
				$array[$name] = array();
				if ( ! empty($rel))
				{
					static::$to_array_references[] = get_class(reset($rel));
					foreach ($rel as $id => $r)
					{
						$array[$name][$id] = $r->to_array($custom, true, $eav);
					}
				}
			}
			else
			{
				if ( ! in_array(get_class($rel), static::$to_array_references))
				{
					if (is_null($rel))
					{
						$array[$name] = null;
					}
					else
					{
						static::$to_array_references[] = get_class($rel);
						$array[$name] = $rel->to_array($custom, true, $eav);
					}
				}
			}
		}

		// get eav relations
		if ($eav and property_exists(get_called_class(), '_eav'))
		{
			// loop through the defined EAV containers
			foreach (static::$_eav as $rel => $settings)
			{
				// normalize the container definition, could be string or array
				if (is_string($settings))
				{
					$rel = $settings;
					$settings = array();
				}

				// determine attribute and value column names
				$attr = \Arr::get($settings, 'attribute', 'attribute');
				$val  = \Arr::get($settings, 'value', 'value');

				// check if relation is present
				if (array_key_exists($rel, $array))
				{
					// get eav properties
					$container = \Arr::assoc_to_keyval($array[$rel], $attr, $val);

					// merge eav properties to array without overwritting anything
					$array = array_merge($container, $array);

					// we don't need this relation anymore
					unset($array[$rel]);
				}
			}
		}

		// strip any excluded values from the array
		foreach (static::$_to_array_exclude as $key)
		{
			if (array_key_exists($key, $array))
			{
				unset($array[$key]);
			}
		}

		return $array;
	}