$ user-> height = 5.10
print_r(explode('.',$user->height))
数组([0] => 5 [1] => 1)
如何让第二个值显示为10?
FYI
print_r(explode('.',5.10))
输出相同的内容。
答案 0 :(得分:2)
你正试图爆炸一个数字。
该数字将0作为一个数字丢弃,因为它与数字无关。您必须将您的号码转换为字符串,然后在必要时填充它。
$number = 5.10;
$string_version = number_format((float)$number, 2, '.', '');
print_r(explode('.', $string_version));
答案 1 :(得分:0)
的print_r(爆炸( '',5.10))
在值爆炸之前删除尾随零。只要不使用String,就会省略尾随零。
<?php
$height = 5.10;
header( "Content-Type: text/plain" );
// Outputs: height = 5.1
echo( "height = " . $height . "\r\n" );
print_r( explode( ".", $height ) );
?>