使用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
更改
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>';
您应该只使用<table>
,这是[[精确地 <table>
的含义。
您要么将所有输出包装在<pre>
标记中,要么使用white-space: pre;
CSS属性。
根据您的情况,<table>
可能更可取。
pre标记
echo '<pre>';
foreach ( $matrix as $baris ) {
foreach ( $baris as $bar ) {
echo round( $bar, 4 ) . '\t';
}
echo '<br>';
}
echo '</pre>';