i am writing a php code that loops an array of variables using foreach and I am trying to get the name of variable to use it in the javascript code here's my code
$arr = array($devices1, $devices2, $devices3, $devices4, $devices5, $devices6);
foreach ($arr as $key => $value)
{
if($value == '1')
{
echo "
<script type=\"text/javascript\">
document.getElementById($key).checked = true;
</script>
";
}
}
when i run the code, $key takes values 0,1,2 what i need is to take devices1, devices2, devices3... so the names of the variables. Can anyone help me out?
devices4 ....n times there is already a chance that this could be written betterchecked == true;should most likely bechecked = true;