直接从表单插入php数组

直接从表单插入php数组,php,arrays,insert,Php,Arrays,Insert,是否可以在不需要数据库的情况下直接将数组插入php文件。ie mysql 代码如下所示: <?php $users = array(); $users["stephanie"] = array( "first name" => "Stephanie", "city" => "Greater London", ); // << insert new records here after this. **is it Possible?** >> ?>

是否可以在不需要数据库的情况下直接将数组插入php文件。ie mysql

代码如下所示:

<?php
$users = array();
$users["stephanie"] = array(
"first name" => "Stephanie",
"city" => "Greater London",
);
// << insert new records here after this. **is it Possible?** >>
?>
<form method="POST">
<p>Name: <input type="text" name="name"></p>
<p>City: <input type="text" name="city"></p>
</form>

姓名:

城市:


直接从上面的表单插入。有没有可能

你可以这样做

<?php
if(!empty($_POST['name'])){
    $users = array();
    $users[$_POST['name']] = array(
    "first name" => $_POST['name'],
    "city" => $_POST['city'],
    );
print_r($users);
}
// << Put insert records here. I don't know how you want to put it and why you need arrays. >>
?>
<form method="POST" action="index.php">  
<p>Name: <input type="text" name="name"></p>
<p>City: <input type="text" name="city"></p>
<input type="submit" value="submit"/>
</form>

你想在这里做什么?你可以使用session。如果是这样,如何将它插入到上面的数组集合中?你的问题还不清楚。您想将数据存储在文件中而不是数据库中吗?是的,将数据存储在文件中。谢谢,我遵循mongodb原则设置了数据库名称。显然,尝试以下格式是行不通的。插入->数组([$\u POST[“name”]…等等。只需阅读注释。目的是存储插入的每个用户详细信息,存储在下面的行中。