$s = "123456789";
$ex = preg_split("//", $s);
$x = 0;
foreach( $ex as $k ) {
$x += $k;
}
echo $x."\n";
?>
上面写了一个差不多的..
主要用preg_split打散数字串,然后用foreach加起来
$s = "123456789";
$l = strlen($s);
$n = 0;
for ($i = 0; $i<$l; $i++)
$n += $s{$i};
echo $n;
?>
$str = str_replace(",","+","1,9,8,4,1,2,3,1");
$sum = eval("return {$str};");
先把数据分隔 在 一个个的取出来 最后计算