我不太熟悉php,但我知道我们可以通过php找到给定数字的位置值。例如,如果输入是23.56,它应该回显2-10,3-1,5-1,6-千分之一.
任何想法都将不胜感激。*请提供帮助。
发布于 2014-09-12 06:20:09
试一试
$str = '23.56';
$strdiv = explode('.', $str);
$before = array('Tens', 'Ones');
$after = array('Hundredths', 'Thousandths');
$counter = 0;
foreach($strdiv as $v) {
for($i=0; $i<strlen($v); $i++) {
if(!empty($v)) {
if($counter == 0) {
$newarr[] = substr($v,$i, 1).' - '.$before[$i];
}
if($counter == 1) {
$newarr[] = substr($v,$i, 1).' - '.$after[$i];
}
}
}
$counter++;
}
echo implode(', ',$newarr); //2 - Tens, 3 - Ones, 5 - Hundredths, 6 - Thousandths
发布于 2014-09-12 06:30:02
<?php
$mystring = '123.64';
$findme = '.';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of '.' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
发布于 2014-09-12 06:44:25
另一种方法:
$num = 23.56;
$arr = array("Tens","Ones","Hundredths","Thousandths");
$num = str_replace(".","",$num);
for ($i=0;$i<strlen($num);$i++) {
$res[] = $num[$i] ." - ".$arr[$i];
}
echo implode(', ',$res);
https://stackoverflow.com/questions/25801703
复制相似问题