-8

I have a variable like this in foreach

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

Output is

apple                   fruit
tomato                   fruit
pineapple                   fruit

How I want is

    apple                   fruit
    tomato                  fruit
    pineapple               fruit

How can I achieve it?

Mahesh Mohan
  • 103
  • 3
  • 9

1 Answers1

1

"\t" is not a viable option but @Magnus Eriksson gave good answer:

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
Jan Myszkier
  • 2,714
  • 1
  • 16
  • 23