PHP中变量之间的换行符

时间:2018-07-27 11:59:50

标签: php whitespace spaces

我在foreach中有一个这样的变量

$variable=$variable1."               ".$variable2;

输出为

apple                   fruit
tomato                   fruit
pineapple                   fruit

我想要的是

    apple                   fruit
    tomato                  fruit
    pineapple               fruit

如何实现?

1 个答案:

答案 0 :(得分:1)

“ \ t”不是一个可行的选择,但是@Magnus Eriksson给出了很好的答案:

echo "\t".$var1."\t".$var2.PHP_EOL

   apple   fruit
   tomato   fruit
   pineapple   fruit

echo ' '.str_pad($var1,20," ").$var2.PHP_EOL

  apple               fruit
  tomato              fruit
  pineapple           fruit