How can white spaces and HTML tags affect the output of PHP arrays?

White spaces and HTML tags can affect the output of PHP arrays by causing unexpected formatting issues or errors in the output. To avoid these problems, it's important to ensure that there are no extra white spaces or HTML tags within the array elements or when echoing the array values.

<?php
// Example of how white spaces and HTML tags can affect PHP arrays
$array = array(
    'key1' => 'value1',
    'key2' => ' value2 ',
    'key3' => '<strong>value3</strong>'
);

// Incorrect way to output array values
foreach($array as $key => $value) {
    echo $key . ': ' . $value . '<br>';
}

// Correct way to output array values
foreach($array as $key => $value) {
    echo $key . ': ' . trim($value) . '<br>';
}
?>