PHP how to loop through a post array(PHP如何遍历post数组)
问题描述
我需要遍历一个 post 数组并将其求和.
I need to loop through a post array and sumbit it.
#stuff 1
<input type="text" id="stuff" name="stuff[]" />
<input type="text" id="more_stuff" name="more_stuff[]" />
#stuff 2
<input type="text" id="stuff" name="stuff[]" />
<input type="text" id="more_stuff" name="more_stuff[]" />
但我不知道从哪里开始.
But I don't know where to start.
推荐答案
您可以这样做:
foreach( $_POST as $stuff ) {
if( is_array( $stuff ) ) {
foreach( $stuff as $thing ) {
echo $thing;
}
} else {
echo $stuff;
}
}
这会处理 $_POST
中传递的变量和数组.
This looks after both variables and arrays passed in $_POST
.
这篇关于PHP如何遍历post数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!