looking for matched item in nesty array configuration

@param array $elements
@param Strng $after
@param Fluent $item
@param array $buffer
@param array $return
@param String $current
@return array
331085
protected function lookInDeep(array $elements, $after, $item, &$buffer = [], &$return = '', $current = null)
    {
        $branch = array();

        foreach ($elements as $key => $element) {
            $return = strlen($return) <= 0 ? $current : $return . '.' . $current;
            if ($return . '.' . $key == $after) {
                $this->buffer($buffer, $elements, $item, $after, $current);
            }
            if ($element instanceof Fluent) {
                $element = $element->toArray();
            }
            if (!empty($element['childs'])) {
                $children = $this->lookInDeep($element['childs'], $after, $item, $buffer, $return, $key);
                if ($children) {
                    $element[$key]['childs'] = $children;
                }
            } else {
                $return = '';
            }

            $branch[$key] = $element;
        }

        return $branch;
    }
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;
    }
528721
public function insertAfter($element)
    {
        $e = self::create($element);
        $newnodes = array();
        foreach ($e as $i => $node) {
            /** @var \DOMNode $node */
            $refnode = $node->nextSibling;
            foreach ($this as $newnode) {
                /** @var \DOMNode $newnode */
                $newnode = static::importNewnode($newnode, $node, $i);
                if ($refnode === null) {
                    $node->parentNode->appendChild($newnode);
                } else {
                    $node->parentNode->insertBefore($newnode, $refnode);
                }
                $newnodes[] = $newnode;
            }
        }
        return self::create($newnodes);
    }
122682
function query(element, elementQuery) {
  if (!element.content) {
    return [];
  }

  if (!lodash.isArray(element.content)) {
    return [];
  }

  const results = lodash.where(element.content, elementQuery);

  return lodash
    .chain(element.content)
    .map((nestedElement) => {
      return query(nestedElement, elementQuery);
    })
    .flatten()
    .concat(results)
    .value();
}
11896
function after (el, newEl) {
  if (typeof newEl === 'string') {
    return el.insertAdjacentHTML('afterend', newEl)
  } else {
    var next = el.nextSibling
    if (next) {
      return el.parentNode.insertBefore(newEl, next)
    } else {
      return el.parentNode.appendChild(newEl)
    }
  }
}
940575
protected function searchAndReplacePlaceHolders(array $element, array $placeHolders)
    {
        array_walk_recursive($element, function(&$v, $k, $ph){
            if (is_string($v) && array_key_exists($v, $ph)) {
                $v = $ph[$v];
            }
        }, $placeHolders);
        return $element;
    }
830297
protected function checkStartHashElement($data)
    {
        $this->checkStart('hashElement', $data, array('document', 'objectElement', 'hashElement', 'list'));

        $last = count($this->stack) - 2;
        if ($this->stack[$last][0] !== 'list') {
            // Ensure hash element type only occurs once outside of lists
            if (isset($this->stack[$last][2][$data])) {
                throw new Exceptions\OutputGeneratorException(
                    "Element {$data} may only occur once inside of {$this->stack[$last][0]}."
                );
            }
        }
        $this->stack[$last][2][$data] = true;
    }
883638
function contains($item, callable $callback = null) {
        if ($callback === null) {
            $callback = __NAMESPACE__ . '\\compare';
        }
        foreach ($this->avl as $pair) {
            /**
             * @var Pair $pair
             */
            if (call_user_func($callback, $pair->second, $item) === 0) {
                return true;
            }
        }

        return false;
    }
1143659
public function process(array $items)
    {
        $total = count($items);
        for ($i = 1; $i < $total; $i++) {
            for ($j = 0; $j < $total - $i; $j++) {
                if (!$items[$j]->getDate() || !$items[$j + 1]->getDate()) {
                    continue;
                }
                if ($items[$j]->getDate()->getTimestamp() > $items[$j + 1]->getDate()->getTimestamp()) {
                    continue;
                }
                $aux = $items[$j + 1];
                $items[$j + 1] = $items[$j];
                $items[$j] = $aux;
            }
        }

        return $items;
    }
325101
public function readGroups(string $before, string $start, string $end, string $after)
    {
        // init
        $groups = [];
        $group = [];
        $position = 'before_search';

        foreach ($this->parsedfile as $edi_row) {
            // search before group segment
            if ($position == 'before_search' && $edi_row[0] == $before) {
                $position = 'before_is';
                continue;
            }

            if ($position == 'before_search') {
                continue;
            }

            if ($position == 'before_is' && $edi_row[0] == $before) {
                continue;
            }

            // after before search start
            if ($position == 'before_is' && $edi_row[0] == $start) {
                $position = 'group_is';
                $group[] = $edi_row;
                continue;
            }

            // if after before segment no start segment, search again before segment
            if ($position == 'before_is') {
                $position = 'before_search';
                continue;
            }

            // get group element
            if ($position == 'group_is' && $edi_row[0] != $end) {
                $group[] = $edi_row;
                continue;
            }

            // found end of group
            if ($position == 'group_is' && $edi_row[0] == $end) {
                $position = 'group_finish';
                $group[] = $edi_row;
                $groups[] = $group;
                $group = [];
                continue;
            }

            // next group start
            if ($position == 'group_finish' && $edi_row[0] == $start) {
                $group[] = $edi_row;
                $position = 'group_is';
                continue;
            }

            // finish
            if ($position == 'group_finish' && $edi_row[0] == $after) {
                break;
            }

            $this->errors[] = 'Reading group ' . $before . '/' . $start . '/' . $end . '/' . $after
                              . '. Error on position: ' . $position;

            return false;
        }

        return $groups;
    }
687004
private function _lookupRecursive($item)
        {
            if (Arrays::is($item)) {
                $collection = array();
                foreach ($item as $k => $v) {
                    $collection[$k] = $this->_lookupRecursive($v);
                }
                return $collection;
            } else {
                return $this->lookup($item);
            }
        }
256823
protected static function pregReplaceElements($regexp, $Elements, $text)
    {
        $newElements = array();

        while (preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE))
        {
            $offset = $matches[0][1];
            $before = substr($text, 0, $offset);
            $after = substr($text, $offset + strlen($matches[0][0]));

            $newElements[] = array('text' => $before);

            foreach ($Elements as $Element)
            {
                $newElements[] = $Element;
            }

            $text = $after;
        }

        $newElements[] = array('text' => $text);

        return $newElements;
    }
1153323
protected function locate($item): ?ItemBucket
    {
        for ($this->rewind(); $this->valid(); $this->next()) {
            /** @var ItemBucket $current */
            $current = $this->current;
            if (Validate::areEqual($item, $current->item())) {
                return $current;
            }
        }

        return null;
    }
1002130
public function process(array $items)
    {
        foreach ($items as $key => $item) {
            $items[$key] = $this->doClean($item);
        }

        return $items;
    }
339192
protected function matches($other): bool
    {
        if (is_array($other)) {
            $success = null;
            foreach ($other as $item) {
                $currentSuccess = $this->matchesSection($item);
                $success = ($success === null ? $currentSuccess : $success || $currentSuccess);
            }
            return !empty($success);
        } else {
            return $this->matchesSection($other);
        }
    }
563744
private function findItemIn($item, $key)
	{
		$array = $this->find($key);
		if($array) return $this->array_get($array, $item);
		return false;
	}
520678
private function parseArrayToFieldEntity(array $item, $elementType)
    {
        $entity = new Field();
        $entity->set($item);
        $entity->element_type = $elementType;

        return $entity;
    }