Tab \ t在php中不起作用

问题描述 投票:0回答:4

使用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>';
} ?>

我得到以下内容:

“”

当我使用CSS时:

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

结果:

“”

我想要这样的结果:

0.4444    0.25    3
0.62      0.5     5.33
2         0.91    3.3333
php
4个回答
1
投票

更改

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>';

3
投票

您应该只使用<table>,这是[[精确地 <table>的含义。


1
投票
空格,包括标签,在HTML中折叠。

您要么将所有输出包装在<pre>标记中,要么使用white-space: pre; CSS属性。

根据您的情况,<table>可能更可取。


0
投票
在循环前添加

pre标记

echo '<pre>'; foreach ( $matrix as $baris ) { foreach ( $baris as $bar ) { echo round( $bar, 4 ) . '\t'; } echo '<br>'; } echo '</pre>';
© www.soinside.com 2019 - 2024. All rights reserved.