0

我正在使用关联数组来存储数据,但我在另一个关联数组中使用关联数组我的代码是这样的

$field2 = array();

        for ($i = 0; $i < $numberofFilreds; $i++) {

            $fname = $this->input->post('mytext' . $i);

            array_push($field2, $fname = array(
                'type' => $this->input->post('DataTypes' . $i),
                'null' => TRUE,
            ));
        } 

当我运行我的代码时,我得到这样的数组

array(1) { [0]=> array(2) { ["type"]=> string(4) "text" ["null"]=> bool(true) } }

问题是我想要[0]=> array(2)这样["Name"]=> array(2)我不知道该怎么做请帮助我

4

2 回答 2

1

所以只需使用$field2["Name"] = array(...). Name用您的唯一索引替换。

for ($i = 0; $i < $numberofFilreds; $i++) {
    $fname = $this->input->post('mytext' . $i);
    $field2[$fname] = array(
        'type' => $this->input->post('DataTypes' . $i),
        'null' => TRUE,
    ));
}
于 2013-08-20T07:26:11.213 回答
0

如果您的$fnamevar 是唯一的,请像这样使用:

$fname = $this->input->post('mytext' . $i);
$$field2[$fname] = array(
        'type' => $this->input->post('DataTypes' . $i),
        'null' => TRUE,
    );
于 2013-08-20T07:27:27.137 回答