根据一组一维数组的值取另一个多维数组对应键名的值并组成新数组

@param array $keys
一维数组
@param array $array
多维数组
@param bool $setNull
键名在数组中不存在时是否加入返回数组
@return array
324285
public static function extract(array $keys, array $array, bool $setNull = false)
    {
        $newArray = [];
        foreach ($keys as $key) {
            if (array_key_exists($key, $array)) {
                $newArray[$key] = $array[$key];
            } else if ($setNull) {
                $newArray[$key] = null;
            }
        }
        return $newArray;
    }
973219
private function getIn(array $array, array $keys, $default = null)
    {
        if (!$keys) {
            return $array;
        }

        // This is a micro-optimization, it is fast for non-nested keys, but fails for null values
        if (\count($keys) === 1 && isset($array[$keys[0]])) {
            return $array[$keys[0]];
        }

        $current = $array;
        foreach ($keys as $key) {
            if (!\is_array($current) || !\array_key_exists($key, $current)) {
                return $default;
            }

            $current = $current[$key];
        }

        return $current;
    }
1198427
public function toExt($data, $key = null, $array = false)
	{
		return $this->to(self::EXT, $data, $key, $array);
	}
1188674
public static function arrayOnlyWith(array $array, array $keys)
    {
        $result = array();

        if (!self::isSequential($array)) {
            foreach ($array as $key => $value) {
                if (in_array($key, $keys)) {
                    $result[$key] = $value;
                }
            }
        } else {
            foreach ($array as $value) {
                if (in_array($value, $keys)) {
                    $result[] = $value;
                }
            }
        }

        return $result;
    }
488727
public function clear(array $keys=null)
    {
        if ($keys === null) {
            $this->_attributes = [];
            return $this;
        }

        if (!$keys) {
            return $this;
        }

        foreach ($keys as $key) {
            if (array_key_exists($key, $this->_attributes)) {
                $this->offsetUnset($key);
            }
        }

        return $this;
    }
660551
private function narrowArray(array $array, string $key = null)
    {
        if ($key) {
            $key .= '--';
        }

        $result = [];

        foreach ($array as $index => $value) {
            if (is_array($value)) {
                $result = array_merge($result, $this->narrowArray($value, $key . $index));
            } else {
                $result[$key . $index] = $value;
            }
        }

        return $result;
    }
464619
public static function update(array $array, string $key, callable $callback)
    {
        $keys = explode('.', $key);
        $current = &$array;

        foreach ($keys as $key) {
            if (! isset($current[$key])) {
                return $array;
            }

            $current = &$current[$key];
        }

        $current = $callback($current);

        return $array;
    }
1273690
private function iteratorFromKeys(array $keys)
    {
        $values = [];
        $key    = ($this->request->qtype === 'eq')
            ? $this->request->key
            : null;

        foreach ($keys as $value) {
            $entry = new IndexEntry();

            $entry->indexKey  = $key;
            $entry->objectKey = $value;

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
1358684
public static function getObjectWithKey(array $array, $key)
    {
        foreach ($array as $object) {
            if (is_array($object) && array_key_exists($key, $object)) {
                return $object;
            }
        }

        return null;
    }
1135840
protected function setIntoArray(&$array, $keys, $value)
    {
        $k = array_shift($keys);

        if (is_scalar($array)) {
            $array = (array) $array;
        }

        if (!isset($array[$k])) {
            $array[$k] = null;
        }

        if (empty($keys)) {
            return $array[$k] = &$value;
        }

        return $this->setIntoArray($array[$k], $keys, $value);
    }
1181280
public static function get($array, $key, $default = null) {
        $keys = explode(".", $key);
        $level = &$array;
        $length = count($keys);
        foreach($keys as $index => $key) {
            if (!is_array($level)) {
              return null;
            }

            if(array_key_exists($key, $level)) {
                if($index == $length-1) {
                    return $level[$key];
                } else {
                    $level = &$level[$key];
                }
            } else {
                return $default;
            }
        }
        return $default;
    }
1340129
public function setQueryKeys(array $keys)
    {
        $this->queryKeys = [];

        foreach ($keys as $key) {
            if (is_string($key)) {
                $this->addQueryKey($key);
            }
        }

        return $this;
    }
661599
public function clear(array $keys=null)
    {
        if ($keys === null) {
            foreach ($this->storages as $storage) {
                $storage->clear();
            }
            return $this;
        }

        if (!$keys) {
            return $this;
        }

        foreach ($keys as $key) {
            $this->offsetUnset($key);
        }

        return $this;
    }
14889
public function set(array $array, $keys, $value)
    {
        $keys = $this->parseKeys($keys);

        if ($keys) {
            $key = array_shift($keys);

            // This is the last key we've shifted
            if (!$keys) {
                $array[$key] = $value;
            } else {
                // There are more keys so this should be an array
                if (!isset($array[$key]) || !is_array($array[$key])) {
                    $array[$key] = array();
                }
                $array[$key] = $this->set(
                    $array[$key], $keys, $value
                );
            }
        }

        return $array;
    }
217101
public function store($updateNulls = false)
    {
        $k = $this->getKeyName();

        /*
         * If the primary key is empty, then we assume we are inserting a new node into the
         * tree.  From this point we would need to determine where in the tree to insert it.
         */
        if (empty($this->$k)) {
            /*
             * We are inserting a node somewhere in the tree with a known reference
             * node.  We have to make room for the new node and set the left and right
             * values before we insert the row.
             */
            if ($this->locationId < 0) {
                // Negative parent ids are invalid
                throw new NestedHandleException(sprintf('%s::store() used a negative _location_id', get_class($this)));
            }

            // We are inserting a node relative to the last root node.
            if ($this->locationId == 0) {
                // Get the last root node as the reference node.
                $query = $this->db->getQuery(true)
                    ->select($this->getKeyName() . ', parent_id, level, lft, rgt')
                    ->from($this->db->quoteName($this->table))
                    ->where('parent_id = 0')
                    ->order('lft DESC')
                    ->limit(1);

                $this->db->setQuery($query);

                $reference = $this->db->loadOne();
            } else {
                // We have a real node set as a location reference.
                // Get the reference node by primary key.
                if (!$reference = $this->getNode($this->locationId)) {
                    throw new NestedHandleException('Cannot get node by location id: ' . $this->locationId);
                }
            }

            // Get the reposition data for shifting the tree and re-inserting the node.
            if (!($repositionData = $this->getTreeRepositionData($reference, 2, $this->location))) {
                throw new NestedHandleException('Cannot get reposition data.');
            }

            // Create space in the tree at the new location for the new node in left ids.
            $query = $this->db->getQuery(true)
                ->update($this->db->quoteName($this->table))
                ->set('lft = lft + 2')
                ->where($repositionData->left_where);

            $this->db->setQuery($query)->execute();

            // Create space in the tree at the new location for the new node in right ids.
            $query->clear()
                ->update($this->db->quoteName($this->table))
                ->set('rgt = rgt + 2')
                ->where($repositionData->right_where);

            $this->db->setQuery($query)->execute();

            // Set the object values.
            $this->parent_id = $repositionData->new_parent_id;
            $this->level = $repositionData->new_level;
            $this->lft = $repositionData->new_lft;
            $this->rgt = $repositionData->new_rgt;
        } else {
            /*
             * If we have a given primary key then we assume we are simply updating this
             * node in the tree.  We should assess whether or not we are moving the node
             * or just updating its data fields.
             */

            // If the location has been set, move the node to its new location.
            if ($this->locationId > 0) {
                $this->moveByReference($this->locationId, $this->location, $this->$k);
            }
        }

        return parent::store($updateNulls);
    }
1332096
public static function get(array $array, ...$keys)
    {
        $key = array_shift($keys);

        if (!isset($array[$key])) {
            return null;
        }

        if (empty($keys)) {
            return $array[$key] ?? null;
        }

        if (!\is_array($array[$key])) {
            return null;
        }

        return self::get($array[$key], ...$keys);
    }
830930
public function get(array $array, $keys, $default = null)
    {
        $keys = $this->parseKeys($keys);

        if (is_array($array) && $keys) {
            $key = array_shift($keys);
            if (array_key_exists($key, $array)) {
                $value = $array[$key];
                if (!$keys) {
                    return $value;
                }

                if (is_array($value)) {
                    return $this->get($value, $keys, $default);
                }
            }
        }

        return $default;
    }