src/Leevel/View/Compiler.php
public function foreachCodeCompiler(array &$theme): void
    {
        $theme['content'] = call_user_func(
            function ($content) {
                preg_match_all('/\\$([\S]+)/', $content, $matches);

                $matches = $matches[1];
                $num = count($matches);

                if ($num > 0) {
                    if (2 === $num) {
                        $result = "\${$matches[1]}";
                    } elseif (3 === $num) {
                        $result = "\${$matches[1]} => \${$matches[2]}";
                    } else {
                        throw new InvalidArgumentException('The parameter of code.foreach tag can be at most three.');
                    }

                    return "if (is_array(\${$matches[0]})): foreach(\${$matches[0]} as {$result})";
                }
            },
            $theme['content']
        );

        $theme['content'] = $this->encodeContent(
            $this->withPhpTag($theme['content'].':')
        );
    }
public function foreachCodeCompiler(array &$theme): void
    {
        $theme['content'] = call_user_func(
            function ($content) {
                preg_match_all('/\\$([\S]+)/', $content, $matches);

                $matches = $matches[1];
                $num = count($matches);

                if ($num > 0) {
                    if (2 === $num) {
                        $result = "\${$matches[1]}";
                    } elseif (3 === $num) {
                        $result = "\${$matches[1]} => \${$matches[2]}";
                    } else {
                        throw new InvalidArgumentException('The parameter of code.foreach tag can be at most three.');
                    }

                    return "if (is_array(\${$matches[0]})): foreach(\${$matches[0]} as {$result})";
                }
            },
            $theme['content']
        );

        $theme['content'] = $this->encodeContent(
            $this->withPhpTag($theme['content'].':')
        );
    }
foreach.

@param array $theme