Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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_Quote - Fatal编程技术网

Javascript 带引号的Php嵌套代码

Javascript 带引号的Php嵌套代码,javascript,php,quote,Javascript,Php,Quote,我有一些代码块在嵌套时遇到问题: return 'autoOpenPopup: '.!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL.''; 这将打印false(autoOpenPopup变量的结果),而不是: autoOpenPopup: false 如果我这样做,它会起作用: $t = !

我有一些代码块在嵌套时遇到问题:

return 'autoOpenPopup: '.!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL.'';
这将打印false(autoOpenPopup变量的结果),而不是:

autoOpenPopup: false
如果我这样做,它会起作用:

$t = !empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL;

return 'autoOpenPopup: '.$t.'';

但我希望嵌套这是可能的。

将您的条件添加到括号中,然后键入cast Boolean to String

return 'autoOpenPopup: '.(string) (!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL);

将条件添加到括号中,然后键入cast Boolean to String

return 'autoOpenPopup: '.(string) (!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL);

试着用括号“(…)”把三元数括起来


试着用括号“(…)”把三元数括起来


编写代码时要记住的一点是使代码易于理解并具有可读性,有时最好选择两行而不是一行。您是否尝试过将三元代码包装到
?。类似这样:
返回“autoOpenPopup:”。(!empty.:…PHP_EOL.')你能快速解释一下int-to-bool的功能吗?(它是否将
1
转换为
true
(字符串)-
0
转换为
false
(字符串)?公共函数int\u转换为bool($value){返回空($value)-'false':'true';}编写代码时要记住的一件事是使代码易于理解并具有可读性,有时最好选择两行而不是一行。您是否尝试过将三元代码包装到
?。例如:
返回“autoOpenPopup:”。(!empty.:…PHP_EOL.)
你能快速解释一下
int-to-bool
的功能吗?(它是否将
1
转换为
true
(字符串)和
0
转换为
false
(字符串)?公共函数int-to-bool($value){返回空($value)'false':'true')为什么op要尝试这个?你改变了什么?请解释你的答案;)当然,谢谢@FirstOne为什么op要尝试这个?你改变了什么?请解释你的答案;)当然,谢谢@FirstOne