I have the following code:
<?php
header ('Content-Type: text/html; charset=UTF-8');
$cars = array("Mike", "Paul", "Rita");
?>
<html>
<head>
<script>
function runFun(){
var t = document.getElementById("t");
let cID = t.selectedIndex;
$c = `<?php echo "I like " . $cars[cID]; ?>`;
$c1 = `<?php echo "I like " . $cars[1]; ?>`;
window.alert($c);
}
</script>
</head>
<body>
<select id="t" onchange="runFun();" name="t">
<option value="<?php echo $cars[0] ?>"><?php echo $cars[0] ?></option>
<option value="<?php echo $cars[1] ?>"><?php echo $cars[1] ?></option>
<option value="<?php echo $cars[2] ?>"><?php echo $cars[2] ?></option>
</select>
<p>
</body>
</html>
I need to pass the selected index cID to php array index in the same page. Is it possible?
Thank you in advance.
Regards
I tried
<?php echo "I like " . $cars[. 'cID' .]; ?>
and
<?php echo "I like " . $cars[+${cID}+]; ?>`;
But non works for me