user3002807
user3002807

Reputation: 23

Tab \t not working in php

When using PHP:

<?php
//coba spasi atau tab
$matrix=array(array(0.4444444,0.25,3),
              array(0.62,0.5,5.33),
              array(2,0.91,3.333333333)
);
//print_r($matrix);
foreach($matrix as $baris){
    foreach($baris as $bar){
        echo round($bar,4)."\t";
    }
    echo '<br>';
} ?>

I get the following:

When I use CSS:

echo round($bar,4).'<span style="display: inline-block; width: 60px;"></span>';

The result:

I want the result like this:

0.4444    0.25    3
0.62      0.5     5.33
2         0.91    3.3333

Upvotes: 1

Views: 4596

Answers (4)

antelove
antelove

Reputation: 3348

Add pre tag before the loop

echo '<pre>';

foreach ( $matrix as $baris ) {

    foreach ( $baris as $bar ) {
        echo round( $bar, 4 ) . '\t';
    }

    echo '<br>';

}

echo '</pre>';

Upvotes: 4

Alex K
Alex K

Reputation: 15848

You should just use a <table>, this is exactly what a <table> is meant for.

Upvotes: 3

mario
mario

Reputation: 145482

Whitespace, including tabs, is collapsed in HTML.

You either need to wrap all the output in a <pre> tag, or use the white-space: pre; CSS property.

In your case, a <table> might be more advisable.

Upvotes: 1

OlivierH
OlivierH

Reputation: 3890

Change

echo round($bar,4).'<span style="display: inline-block; width: 60px;"></span>';

to

echo '<span style="display: inline-block; width: 60px;">'.round($bar,4).'</span>';

Upvotes: 1

Related Questions