打印两个函数,中间有空格


Print 2 functions with a space between

我试图echo 2个函数的返回值之间有一个空间,我试过:

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

但是上面没有输出任何东西。我哪里做错了?

你的代码说"是strtolower(…), ' '和布尔真值的连接吗?"因为总是这样,它应该总是输出yes。避免这种情况的最好方法是不使用连接,而是将单独的参数传递给echo:

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

现在最后一个三元表达式与前两个无关。

把三元组起来。

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

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

result: sometext yes

使用

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

输出函数的结果(TRUE或FALSE)。通过这种方式,您可以输出字符串Yes或No。

我认为你必须把

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

注意is_array

周围的"()"