将结果加载到缓冲区而不回显浏览器

How can I load loop results into a buffer using the PHP output control functions without echoing the results to the browser? In essence, what I'm trying to do is call results from the buffer as opposed to echoing my way through the loop "as it goes". Is it possible to do this? Any help appreciated. Thanks!

Use ob_get_contents to get the buffer contents without sending them.

To clean out the buffer call ob_end_clean

To do both in one step call ob_get_clean

An example would be

ob_start();
foreach ($results as $result){
     include("tmplate/to/render/a/result.php");
}
$resultHTML = ob_get_clean();

Then later.

<div class='left-rail'><?= $resultHtml ?></div>

It's still not clear what you mean, but here's an answer based on past experience with php programmers: PHP is a full programming language, so you can build complex data structures without producing any output. If you're reading rows from a database, you can read them into an array, do whatever you want with the array, then produce output when you're ready.

If you're generating output by scanning through the array in lots of steps, you can gradually build up a string (or more, if that's necessary in your case) and again output them when you know what you want to do.

Something along these lines:

$output = "";
foreach ($my_array as $row) {
    $output .= "<li>".$row."</li>
";
    // plus various checks etc.
}

Am I getting the idea of what you're after?