【发布时间】:2019-01-05 15:29:36
【问题描述】:
我如何轻松地使用 for 循环 php 对下面字符串中的所有值求和?
$modules_m_1 结果应该是:10
$g_module_row_active_1 = 1;
$g_module_row_active_2 = 1;
$g_module_row_active_3 = 1;
$g_module_row_active_4 = 1;
$g_module_row_active_5 = 1;
$g_module_row_active_6 = 1;
$g_module_row_active_7 = 1;
$g_module_row_active_8 = 1;
$g_module_row_active_9 = 1;
$g_module_row_active_10 = 1;
$modules_m_1 = $g_module_row_active_1 + $g_module_row_active_2 + $g_module_row_active_3 + $g_module_row_active_4 + $g_module_row_active_5 + $g_module_row_active_6 + $g_module_row_active_7 + $g_module_row_active_8 + $g_module_row_active_9 + $g_module_row_active_10;
【问题讨论】:
-
不标记它,因为它不是精确重复的,但有一些信息可以帮助您开始回答this similar question。而不是
echo'ing 变量,您需要将它们添加到一个新变量并在循环后处理结果。