What are the potential pitfalls when trying to display previously selected <option> elements in PHP?

When displaying previously selected <option> elements in PHP, the potential pitfall is not properly setting the 'selected' attribute for the option that was previously selected. To solve this issue, you need to check if the value of the option matches the previously selected value and add the 'selected' attribute to that option.

&lt;select name=&quot;dropdown&quot;&gt;
    &lt;option value=&quot;1&quot; &lt;?php echo ($selectedValue == 1) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Option 1&lt;/option&gt;
    &lt;option value=&quot;2&quot; &lt;?php echo ($selectedValue == 2) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Option 2&lt;/option&gt;
    &lt;option value=&quot;3&quot; &lt;?php echo ($selectedValue == 3) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Option 3&lt;/option&gt;
&lt;/select&gt;