name="qty<?php echo $key?>"
foreach ($_POST as $items => $value)
{
// check qty >1???
echo $key, ' => ', $value, '<br />';
}
如何仅显示其值为 [qty1]=>value,[qty2]=>value... >0 的项目?
只需使用组合数组过滤器 http://php.net/manual/en/function.array-filter.php and print_r http://php.net/manual/en/function.print-r.php.
$_POST = [
'notme' => 12,
'qty1' => 1,
'qty2' => 20,
'qty3' => -1,
'qty4' => 0,
'qty5' => 30
];
print_r(
array_filter($_POST, function ($value, $key) {
// check key starts with 'qty' and its value is greater than one
return strpos($key, 'qty') === 0 && $value > 1;
}, ARRAY_FILTER_USE_BOTH)
);
// Array ( [qty2] => 20 [qty5] => 30 )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)