Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Add html code to php variable

$
0
0
Hi all
 
I want to create a simple html select menu from an array like:
 
<select>
  <option value="">Red</option>
  <option value="">Green</option>
  <option value="">Blue</option>
</select>

I know I can output this like:

$my_Arr = array('Red','Green','Blue');


echo "<select>"; 

for($i=0; $i<count($my_Arr); $i++){
  
  echo"<option>".$my_Arr[$i]."</option>";
    
}

echo "</select>";

But I would like to add the select menu to a variable and use later.

 

So I can start the variable off like:

$select_menu = "<select>";

But how can I add the rest of the html code to the variable as it's created, so I end up with:

$select_menu = "<select>
  <option value="">Red</option>
  <option value="">Green</option>
  <option value="">Blue</option>
</select>"

Viewing all articles
Browse latest Browse all 13200

Trending Articles