Example 1 — List Queued Headers
Set a few headers and print headers_list(). The sample output shows what a web SAPI typically returns.
<?php
header("Content-Type: text/plain; charset=UTF-8");
header("X-Demo: 1");
foreach (headers_list() as $line) {
echo $line, PHP_EOL;
} How It Works
- Two headers are queued with header().
- headers_list() returns each line as a string.
- The foreach loop prints one header per line.
- On CLI the loop may print nothing; the output shown is the web-SAPI case.

