I am trying to style what is selected from my array, however when I run my code I get a syntax error and it has to do with my h1 styling I believe. Im trying to Echo a h1 that displays the color name and uses the color name to style the color of the h1 using inline styling to set the color.
<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>;
?>
您的echo陈述式有误,应以""
括起来:
echo "<h1 style = 'color:$differentColor; '>$differentColor</h1>;"
Did you see which line the error is?
Try this:
echo "<h1 style=\"color:$differentColor\">$differentColor</h1>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.