遍历具有相似名称的$ _POST变量 [英] loop through $_POST variables with similar names
本文介绍了遍历具有相似名称的$ _POST变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个$ _POST变量,它们是
I have several $_POST variables, they are
$_POST['item_number1']
$_POST['item_number2']
以此类推
我需要编写一个循环,以显示所有变量的值(我不知道有多少个变量).最简单的方法是什么?如果我知道我有多少个变量,最简单的方法是什么?
I need to write a loop tha displays the values of all the variables (I don't know how many there are). What would be a simplest way to go about it? Also what would be the simplest way if I do know how many variables I have?
推荐答案
这将回显名称以item_number
开头的所有POST参数:
This will echo all POST parameters whose names start with item_number
:
foreach($_POST as $k => $v) {
if(strpos($k, 'item_number') === 0) {
echo "$k = $v";
}
}
PHP手册: foreach()
,
PHP Manual: foreach()
, strpos()
这篇关于遍历具有相似名称的$ _POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文