html - optgroup generated by php -


i'm trying generate optgroups , options php array, , generates it, optgroup wrong. display first word. in page source it's correct.

$my_array = array(     first optgroup => array(         key1 =>value1,         key2 => value2,         key3 => value3,     ),     second optgroup => array(         key1 =>value1,         key2 => value2,         key3 => value3,     ), ); foreach ($my_array $optgroup => $other_array) {     echo "<optgroup label=". $optgroup . ">";      foreach ($other_array $key => $value) {         echo "<option value=" . $key . ">" . $value . "</option>"; }     echo "</optgroup>";  in source code fine:  <optgroup label=first optgroup>     <option value=key1>value1</option>     <option value=key2>value2</option>      ....... 

but on select box see "first", instead of "first optgroup"

any ideas?? thanks!!

you'd need embed quotes:

echo "<optgroup label=\"{$optgroup}\">";                       ^^-----------^^---- 

note backslash escapes on embedded quotes. this'll generate

<optgroup label="foo bar"> 

instead of

<optgroup label=foo bar>                  ^^^--- value "label" attribute                     ^^^---unknown random attribute 

you're doing now


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -