src/Template.php
public function eachTag($tag, $callable)
    {
        if (!$this->hasTag($tag)) {
            return $this;
        }

        // array support
        if (is_array($tag)) {
            foreach ($tag as $t) {
                $this->eachTag($t, $callable);
            }

            return $this;
        }

        // $tag should be string here
        $template = $this->getTagRefList($tag);
        if ($template != $this->template) {
            foreach ($template as $key => $templ) {
                $ref = $tag.'#'.($key + 1);
                $this->tags[$tag][$key] = [call_user_func($callable, $this->recursiveRender($templ), $ref)];
            }
        } else {
            $this->tags[$tag][0] = [call_user_func($callable, $this->recursiveRender($template), $tag)];
        }

        return $this;
    }
public function eachTag($tag, $callable)
    {
        if (!$this->hasTag($tag)) {
            return $this;
        }

        // array support
        if (is_array($tag)) {
            foreach ($tag as $t) {
                $this->eachTag($t, $callable);
            }

            return $this;
        }

        // $tag should be string here
        $template = $this->getTagRefList($tag);
        if ($template != $this->template) {
            foreach ($template as $key => $templ) {
                $ref = $tag.'#'.($key + 1);
                $this->tags[$tag][$key] = [call_user_func($callable, $this->recursiveRender($templ), $ref)];
            }
        } else {
            $this->tags[$tag][0] = [call_user_func($callable, $this->recursiveRender($template), $tag)];
        }

        return $this;
    }
public function eachTag ( $ tag , $ callable ) { if ( ! $ this -> hasTag ( $ tag ) ) { return $ this ; } // array support if ( is_array ( $ tag ) ) { foreach ( $ tag as $ t ) { $ this -> eachTag ( $ t , $ callable ) ; } return $ this ; } // $tag should be string here $ template = $ this -> getTagRefList ( $ tag ) ; if ( $ template != $ this -> template ) { foreach ( $ template as $ key => $ templ ) { $ ref = $ tag . '#' . ( $ key + 1 ) ; $ this -> tags [ $ tag ] [ $ key ] = [ call_user_func ( $ callable , $ this -> recursiveRender ( $ templ ) , $ ref ) ] ; } } else { $ this -> tags [ $ tag ] [ 0 ] = [ call_user_func ( $ callable , $ this -> recursiveRender ( $ template ) , $ tag ) ] ; } return $ this ; }
Executes call-back for each matching tag in the template.

@param string|array $tag
@param callable     $callable

@return $this
Executes call - back for each matching tag in the template .