0
我試圖從我的數組中選擇樣式,但是當我運行我的代碼時,出現語法錯誤,它與我相信的h1樣式有關。我試圖回顯顯示顏色名稱的h1,並使用顏色名稱來使用內聯樣式設置h1的顏色來設置顏色。從數組中顯示和設置選定的值
<body>
<form id = '' name = '' action='php 07 array 01.php' method='post' class = ''>
<select id = 'colorNumber' name = 'colorNumber'>
<option value = '0'>0</option>
<option value = '1'>1</option>
<option value = '2'>2</option>
<option value = '3'>3</option>
<option value = '4'>4</option>
<option value = '5'>5</option>
<option value = '6'>6</option>
<option value = '7'>7</option>
<option value = '8'>8</option>
<option value = '9'>9</option>
</select>
<input type = 'submit' value = 'GO' class = '' id = 'go'>
</form>
</body>
<?php
$colorArray = array("sepia", "gold", "carrot", "orange", "yellow", "blue", "pink", "purple", "black", "warmgrey");
$colorEfx = $_POST['colorNumber'];
$differentColor = $colorArray[$colorEfx];
echo <h1 style = 'color:$differentColor; '>$differentColor</h1>;
?>