php问题,求指导


数据库存的字符串 1/10
获取到字符串之后,如何把1/10 转化为0.1 ?

php

Archerf 8 years, 9 months ago

 php


 <?php
function fractionStrToNumber ($str) {
  $numArr = explode('/', $str);
  if(sizeof($numArr) === 2) {
    return $numArr[0] / $numArr[1];
  } else {
    return 0;
  }
}

echo fractionStrToNumber('1/10');

Tony大本 answered 8 years, 9 months ago

php 有eval函数,可以执行

画风都不一样 answered 8 years, 9 months ago

好多种方法,可以explode,然后算

lewlss answered 8 years, 9 months ago

<?php
$a="1/10";
eval("\$a=$a;");
echo $a;

泄矢诹访子 answered 8 years, 9 months ago

eval("echo 1/10;");

fyyoj answered 8 years, 9 months ago

Your Answer