Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在PHP中,分配给布尔值的变量不会回显到网页_Javascript_Php_Get_Boolean - Fatal编程技术网

Javascript 在PHP中,分配给布尔值的变量不会回显到网页

Javascript 在PHP中,分配给布尔值的变量不会回显到网页,javascript,php,get,boolean,Javascript,Php,Get,Boolean,我有一些PHP代码,用来检查是否分配了$\u GET global中的某个值。如果不是,它会自动设置一个预定值。如果存在,则为变量指定默认值: <?php if(!isset($spaceObjects)){ $spaceObjects = 0; } else{ $spaceObjects = $_GET['spaceObjects'] == true; } if(!isset($numOfStars)){ $numOfStars = 100; } else{ $numOf

我有一些PHP代码,用来检查是否分配了$\u GET global中的某个值。如果不是,它会自动设置一个预定值。如果存在,则为变量指定默认值:

<?php
if(!isset($spaceObjects)){
  $spaceObjects = 0;
} else{
  $spaceObjects = $_GET['spaceObjects'] == true;
}
if(!isset($numOfStars)){
  $numOfStars = 100;
} else{
  $numOfStars = intal($_GET['numOfStars']);
}
if(!isset($starTwinkles)){
  $starTwinkles = 0;
} else{
  $starTwinkles = ($_GET ['starTwinkles'] == true);
}
if(!isset($numOfMeteorsMax)){
  $numOfMeteorsMax = 8;
} else{
  $numOfMeteorsMax = intval($_GET['numOfMeteorsMax']);
}
if(!isset($twinklePausing)){
  $twinklePausing = 1;
} else{
  $twinklePausing = ($_GET['twinklePausing'] == true);
}
if(!isset($nightCycle)){
  $nightCycle = 0;
} else{
  $nightCycle = ($_GET['nightCycle'] == true);
}
if(!isset($music)){
  $music = 1;
} else{
  $music = ($_GET['musicEnabled'] == true);
}
if(!isset($nightSounds)){
  $nightSounds = 0;
} else{
  $nightSounds = ($_GET['nightSounds'] == true);
}
if(!isset($nightSoundsVol)){
  $nightSoundsVol = 0.1;
} else{
  $nightSoundsVol = intval($GET['nightSoundsVol']);
}
?>
let controlVariables = {
  spaceObjects: <?php echo $spaceObjects;?>,
  numOfStars: <?php echo $numOfStars;?>,
  starTwinkles: <?php echo $starTwinkles;?>,
  numOfMeteorsMax: <?php echo $numOfMeteorsMax;?>,
  disableTwinklingWhileSpaceObjectGenerated: <?php echo $twinklePausing;?>,
  nightCycle: <?php echo $nightCycle;?>,
  music: <?php echo $music;?>,
  nightSounds: <?php echo $nightSounds;?>,
  nightSoundsVol: <?php echo $nightSoundsVol;?>
};
奇怪的是,PHP在一些echo语句中什么也没给我,导致JS抛出语法错误


为什么PHP不打印true或false而对某些字段不提供任何信息?

尝试用condition替换echo以输出特定文本,而不是变量本身。 当为true时,回显布尔值输出1,当变量为false时,无输出。 e、 g:


这确实有效。由于语法的原因,我不得不对它做了一些修改,但还是要谢谢你。啊,我明白了。Echo不能在三元运算符中使用,请参见答案中的更改代码段。
let controlVariables = {
    spaceObjects: <?php echo ($spaceObjects)? 'true' : 'false';?>,
...
}