While 循环

QueryPHP 支持 while 语法标签,通过这种方式可以很好地将 PHP 的 while 语法布局出来。

code

  1. public function testCode()
  2. {
  3. $parser = $this->createParser();
  4. $source = <<<'eot'
  5. {~$i = 10}
  6. {while $i>0}
  7. {$i}Hello QueryPHP !<br>
  8. {~$i--}
  9. {/while}
  10. eot;
  11. $compiled = <<<'eot'
  12. <?php $i = 10; ?>
  13. <?php while ($i>0): ?>
  14. <?php echo $i; ?>Hello QueryPHP !<br>
  15. <?php $i--; ?>
  16. <?php endwhile; ?>
  17. eot;
  18. $this->assertSame($compiled, $parser->doCompile($source, null, true));
  19. }

node

  1. public function testNode()
  2. {
  3. $parser = $this->createParser();
  4. $source = <<<'eot'
  5. {~$i = 10}
  6. <while condition="$i gt 0">
  7. {$i}Hello QueryPHP !<br>
  8. {~$i--}
  9. </while>
  10. eot;
  11. $compiled = <<<'eot'
  12. <?php $i = 10; ?>
  13. <?php while($i > 0): ?>
  14. <?php echo $i; ?>Hello QueryPHP !<br>
  15. <?php $i--; ?>
  16. <?php endwhile; ?>
  17. eot;
  18. $this->assertSame($compiled, $parser->doCompile($source, null, true));
  19. }