Example 1 — Comma-Separated List
The classic use: turn an array into a readable list.
<?php
$fields = ['lastname', 'email', 'phone'];
$result = implode(', ', $fields);
echo "Result: $result\n";
$items = ['PHP', 'MySQL', 'JavaScript'];
$html = "<ul><li>" . implode("</li><li>", $items) . "</li></ul>";
echo $html . "\n";
?> How It Works
- Pick glue.
", "goes between field names. - Join values. No separator after the last item.
- HTML trick. Glue
</li><li>sits between list items. - Wrap ends. Add opening/closing
<ul>/<li>around the joined middle.

