简体   繁体   English

打印2个功能之间是否有空格?

[英]print 2 functions with a space between?

Im trying to echo the returned value of 2 functions with a space in between, I've tried: 我试图echo显2个函数的返回值,中间有一个空格,我试过了:

class="<?php echo strtolower($class).' '.is_array($arr) ? 'yes' : 'no'; ?>"

But the above doesn't output anything. 但是上面没有输出任何东西。 Where am I going wrong? 我要去哪里错了?

Your code says "is the concatenation of strtolower(…) , ' ' and a boolean truthy?" 您的代码说: “是strtolower(…)' '和布尔真值的串联吗?” And since that's always so, it should always be outputting yes . 既然一直如此,那么应该始终输出yes This can best be avoided by not using concatenation but passing separate arguments to echo : 最好通过不使用串联,而将单独的参数传递给echo来避免:

echo strtolower($class), ' ', is_array($arr) ? 'yes' : 'no';

Now the last ternary expression is unrelated to the previous two. 现在,最后一个三元表达式与前两个无关。

只需将三元部分分组即可。

echo strtolower($class).' '.(is_array($arr) ? 'yes' : 'no');

<?php echo strtolower('someText').' '.(is_array([]) ? 'yes' : 'no'); ?>

结果: sometext是

Use this: 用这个:

class="<?php echo strtolower($class); ?> <?php is_array($arr) ? echo 'yes' : echo 'no'; ?>"

You print out the result of a function (which is TRUE or FALSE). 您打印出一个函数的结果(是TRUE还是FALSE)。 In this way you output a String Yes or No. 这样,您将输出一个字符串Yes或No。

I think you have to put 我想你必须放

class="<?php echo strtolower($class).' '.(is_array($arr) ? 'yes' : 'no'); ?>"

Note the "()" around is_array 注意is_array周围的“()”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM