I'm debating how to use a php array of 39 color names within a javascript code. <?php $COLORS = Array( "Red", "Blue", "Green", "Orange", "Pink", "Sienna", "DarkOliveGreen", "DarkGreen", "DarkSlateBlue", "Navy", "Indigo", "DarkSlateGray", "DarkRed", "DarkOrange", "Olive", "Teal", "SlateGray", "DimGray", "SandyBrown", "YellowGreen", "SeaGreen", "MediumTurquoise", "Purple", "Gray", "Magenta", "Yellow", "Lime", "Cyan", "DeepSkyBlue", "DarkOrchid", "Silver", "Wheat", "LemonChiffon", "PaleGreen", "PaleTurquoise", "LightBlue", "Plum", "Black", "White" ); ?> PHP:
<form action=""> <select name="colors"> [php]<?php foreach ($COLORS as $COLOR){ echo "<option value='$COLOR'>$COLOR</option>"; ?>[/php] </select> </form> Code (markup): you could do something like that and you might have to edit it a little
a straight export without loops / iterations from php into js: <script type="text/javascript"> var COLORS = ['<?=implode("','", $COLORS)?>']; // will print ... = ['Red','Blue',...]; </script> PHP: also useful: consider json_encode / json_decode (look them up on php manual, very handy for transferring of data structures)