PHP - 实际执行变量的值

Dae*_*aos 3 php

我有一系列分数:

$fractions = array('1/8', '1/4', '1/2');
Run Code Online (Sandbox Code Playgroud)

有什么方法可以让PHP实际执行除法获得小数值?

就像是:

foreach($fractions as $value) {
    $decimal = [the result of 1 divided by 8, or whatever the current fraction is in value];
}
Run Code Online (Sandbox Code Playgroud)

Jag*_*age 6

你拥有它的方式,你应该爆炸并做你的分裂:

foreach($fractions as $value) {
    $exp = explode('/',$value);
    $decimal =  $exp[0] /  $exp[1];
}
Run Code Online (Sandbox Code Playgroud)

你也可以eval(),但我通常尽量不这样做.这也是一个性能打击.