PHP如何遍历一个post数组 [英] PHP how to loop through a post array

查看:109
本文介绍了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数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆