How can predefined values be set in a <select> element in PHP forms?

When working with PHP forms, you can set predefined values in a <select> element by using the "selected" attribute within the <option> tag. This attribute allows you to specify which option should be selected by default when the form is loaded. To do this, you need to check if the option value matches the predefined value and add the "selected" attribute accordingly.

&lt;select name=&quot;color&quot;&gt;
    &lt;option value=&quot;red&quot; &lt;?php echo ($color == &#039;red&#039;) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Red&lt;/option&gt;
    &lt;option value=&quot;blue&quot; &lt;?php echo ($color == &#039;blue&#039;) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Blue&lt;/option&gt;
    &lt;option value=&quot;green&quot; &lt;?php echo ($color == &#039;green&#039;) ? &#039;selected&#039; : &#039;&#039;; ?&gt;&gt;Green&lt;/option&gt;
&lt;/select&gt;