Create new Dictionary from array of key-value pairs.

@param   $array      array   Array of pairs. Each pair must be 2-element array.
@return  Dictionary
490374
public static function fromPairs($array)
    {
        if (!is_array($array) && !($array instanceof \Traversable)) {
            throw new \InvalidArgumentException(sprintf(
                'Dictionary::fromPairs() argument must be array or Traversable, '
                . 'but is "%s".', gettype($array)
            ));
        }
        
        $result = new Dictionary();
        foreach ($array as $pair) {
            if (!is_array($pair) || !isset($pair[0]) || !isset($pair[1])) {
                throw new \InvalidArgumentException(
                    'Each element of array or Traversable passed to Dictionary::FromPairs()'
                    . ' must be two-elements array.'
                );
            }
            
            $result[$pair[0]] = $pair[1];
        }
        return $result;
    }
260691
public function arrayToHash($array)
    {
        $hash = [];
        for ($i = 0, $s = sizeof($array) - 1; $i < $s; ++$i) {
            $hash[$array[$i]] = $array[++$i];
        }
        return $hash;
    }
1039860
public static function keys($array, $prefix = null)
    {
        $keys = array_keys($array);

        if (! empty($prefix)) {
            $keys = static::prefix($keys, $prefix);
        }

        return $keys;
    }
476763
public function arrayToObject($array)
    {
        $object = new \stdClass();
        foreach ($array as $k => $v) {
            if (is_array($v)) {
                // load nested elements
                $v = $this->arrayToObject($v);
            }
            $object->{$k} = $v;
        }

        return $object;
    }
157566
public static function flatten(array $array)
    {
        $out = [];

        foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $key => $item) {
            if (is_int($key)) {
                $out[] = $item;
            } else {
                $out[$key] = $item;
            }
        }

        return $out;
    }
1196141
public static function fromArray($array)
    {
        if (!is_array($array) && !($array instanceof \Traversable)) {
            throw new \InvalidArgumentException(sprintf(
                'Dictionary::fromArray() argument must be array or Traversable, '
                . 'but is "%s".', gettype($array)
            ));
        }

        $result = new Dictionary();
        foreach ($array as $key => $value) {
            $result[$key] = $value;
        }
        return $result;
    }
423995
public static function array_pick($array) {
    if (!is_array( $array )) {
      return $array;
    }
    $keys = array_slice(func_get_args(), 1);
    $keys = self::array_flatten($keys);
    $pick = array();
    foreach ( $keys as $key ) {
      if (!array_key_exists($key, $array)) {
        continue;
      }
      $pick[$key] = $array[$key];
    }
    return $pick;
  }
1223587
protected function extractKeys($array): array
    {
        $result = [];
        foreach ($array as $key=>$val) {
            if (is_int($key)) {
                $result[$val] = [];
            } else {
                $result[$key] = $val;
            }
        }

        return $result;
    }
477588
public function recursiveConvertInArray($array)
    {
        $newArray = [];
        foreach ($array as $key => $value) {
            if ($value instanceof \MongoDB\Model\BSONDocument || $value instanceof \MongoDB\Model\BSONArray) {
                $value = (array) $value;
            }

            if (is_array($value)) {
                $value = $this->recursiveConvertInArray($value);
            }

            $newArray[$key] = $value;
        }

        return $newArray;
    }
1185401
public static function createFromArray(array $array): self
    {
        $query = isset($array['coordinate'])
            ? self::createLocated(
                Coordinate::createFromArray($array['coordinate']),
                $array['q'] ?? '',
                (int) ($array['page'] ?? self::DEFAULT_PAGE),
                (int) ($array['size'] ?? self::DEFAULT_SIZE)
            )
            : self::create(
                $array['q'] ?? '',
                (int) ($array['page'] ?? self::DEFAULT_PAGE),
                (int) ($array['size'] ?? self::DEFAULT_SIZE)
            );
        $query->fields = $array['fields'] ?? [];
        $query->aggregations = array_map(function (array $aggregation) {
            return Aggregation::createFromArray($aggregation);
        }, $array['aggregations'] ?? []);

        $query->sortBy = SortBy::createFromArray($array['sort'] ?? []);
        $query->filters = array_merge(
            $query->filters,
            array_map(function (array $filter) {
                return Filter::createFromArray($filter);
            }, $array['filters'] ?? [])
        );
        $query->universeFilters = array_merge(
            $query->universeFilters,
            array_map(function (array $filter) {
                return Filter::createFromArray($filter);
            }, $array['universe_filters'] ?? [])
        );
        $query->resultsEnabled = $array['results_enabled'] ?? true;
        $query->suggestionsEnabled = $array['suggestions_enabled'] ?? false;
        $query->aggregationsEnabled = $array['aggregations_enabled'] ?? true;
        $query->highlightEnabled = $array['highlight_enabled'] ?? false;
        $query->itemsPromoted = array_values(array_map(function (array $itemUUID) {
            return ItemUUID::createFromArray($itemUUID);
        }, $array['items_promoted'] ?? []));
        $query->fuzziness = $array['fuzziness'] ?? null;
        $query->searchableFields = $array['searchable_fields'] ?? [];
        $query->scoreStrategies = isset($array['score_strategies'])
            ? ScoreStrategies::createFromArray($array['score_strategies'])
            : null;
        $query->minScore = $array['min_score'] ?? self::NO_MIN_SCORE;
        $query->metadata = $array['metadata'] ?? [];

        if (isset($array['user'])) {
            $query->user = User::createFromArray($array['user']);
        }

        $query->subqueries = array_map(function (array $query) {
            return Query::createFromArray($query);
        }, $array['subqueries'] ?? []);

        if (isset($array['uuid'])) {
            $query->UUID = $array['uuid'];
        }
        if (isset($array['index_uuid'])) {
            $query->indexUUID = IndexUUID::createFromArray($array['index_uuid']);
        }

        return $query;
    }
796388
protected function createFromArray($array)
    {
        $this->id = $array['id'];
        $this->modelType = $array['modelType'];
        $this->modelId = $array['modelId'];
        $this->name = $array['name'];
        $this->price = $array['price'];
        $this->image = $array['image'];
        $this->quantity = $array['quantity'];

        return $this;
    }
23214
public static function shuffle(array $array)
    {
        if (empty($array)) {
            return $array;
        }
        $result = [];
        $keys = array_keys($array);
        shuffle($keys);
        foreach ($keys as $key) {
            $result[$key] = $array[$key];
        }
        return $result;
    }
269952
public function copyToArray(array &$array)
    {
        $array['name']         = $this->name;
        $array['defaultEntry'] = $this->defaultEntry;
        $array['description']  = $this->description;
        $array['descriptions'] = LanguageUtility::convertArrayOfArrayCopyableToArray($this->descriptions);
        $array['attributes']   = LanguageUtility::convertArrayOfArrayCopyableToArray($this->attributes);
    }
1300763
protected function doCreateObject(array $array)
    {
        $this->data = $array;
        $this->document = new Document($this->data);
        $this->setFunctionalNames()
             ->setAttributes()
             ->setMedia();

        return $this->document;
    }
254036
public static function type($array)
	{
	    $last_key = -1;
	    $type = 'index';

	    foreach( $array as $key => $val )
	    {
	        if( !is_int( $key ) || $key < 0 )
	        {
	            return 'assoc';
	        }

	        if( $type !== 'sparse' ) 
	        {
		        if( $key !== $last_key + 1 ){
		            $type = 'sparse';
		        }
		        $last_key = $key;
		    }
	    }

	    return $type;
	}
588343
public function dictionary($dictionary)
    {
        $this->dictionary = is_array($dictionary) ? $dictionary : json_decode(file_get_contents($dictionary), true);

        return $this;
    }
1137119
public static function createFromArray(array $array): self
    {
        $aggregations = new self(
            $array['total_elements'] ?? 0
        );

        if (isset($array['aggregations'])) {
            foreach ($array['aggregations'] as $aggregationName => $aggregation) {
                $aggregations->addAggregation(
                    $aggregationName,
                    Aggregation::createFromArray($aggregation)
                );
            }
        }

        return $aggregations;
    }