【发布时间】:2020-10-09 08:51:51
【问题描述】:
我有一个关联数组,它有'question'、'maxmark'、'qpno'。 (这是表单提交的 Post 请求数据。)
array (size=3)
'question' => string 'Question one' (length=12)
'maxmark' => string '5' (length=1)
'qpno' => string 'QB345' (length=5)
array (size=3)
'question' => string 'Question two' (length=12)
'maxmark' => string '10' (length=1)
'qpno' => string 'QB345' (length=5)
array (size=3)
'question' => string 'Question three' (length=12)
'maxmark' => string '5' (length=1)
'qpno' => string 'QB345' (length=5)
我有一个变量,$total_mark = 25;
我想从多维关联数组中添加所有'maxmark'并检查它是否等于$total_mark;
if( sum of all maxmark = $total_mark ) {
do this
} else {
do something else
}
请帮忙。
注意:多维数组中的数组数量不同。 maxmark 也是一个“字符串”。
【问题讨论】:
标签: php arrays forms multidimensional-array sum