沃梦达 / 编程问答 / php问题 / 正文

PHP如何遍历post数组

PHP how to loop through a post array(PHP如何遍历post数组)

本文介绍了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数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:PHP如何遍历post数组

基础教程推荐