我有一个数组
Array
(
[0] => 34
[1] => 04:32 PM
[2] => 05:32 PM
[3] => MNL | ITLY
[4] => 2h 10m
[5] => PHP 9,222
[6] => 33
[7] => 04:32 PM
[8] => 04:32 PM
[9] => ITLY | MNL
[10] => 2h 10m
[11] => PHP 7,227
)
如何对索引5和11的值执行算术运算。
答案 0 :(得分:1)
通过使用preg_replace,您可以删除' PHP'部分和来自价值的逗号。
echo preg_replace('| PHP (\d+),(\d+)|', '$1$2', $array[5]) + preg_replace('| PHP (\d+),(\d+)|', '$1$2', $array[11]);
或者如果空格的数量是随机的' \ s'是任何空白字符
echo preg_replace('|\s+PHP\s+(\d+),(\d+)|', '$1$2', $array[5]) + preg_replace('|\s+PHP\s+(\d+),(\d+)|', '$1$2', $array[11]);
或str_replace()