- ob_start: documentation ( source)
- ob_get_contents: documentation ( source)
- ob_end_clean: documentation ( source)
<?php
foreach([1 => 'test', 2 => 'test'] as $count=>$test){
ob_start();
echo $count;
$cached = ob_get_contents();
ob_end_clean();
echo $cached;
}