How can code tags be used to properly format PHP code for outputting JSON data in a forum or webpage?

To properly format PHP code for outputting JSON data in a forum or webpage, code tags can be used to ensure the code is displayed correctly and maintains its structure. By enclosing the PHP code within code tags, it will be displayed in a monospaced font and maintain its indentation, making it easier for others to read and understand.

<?php
$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'johndoe@example.com'
);

header('Content-Type: application/json');
echo json_encode($data);
?>