如何在PHP中将数据动态添加到数组中
问题描述:
I want to add new data to an array dynamically using HTML and PHP
Here is my code:
<form action="" method="">
<input type="text" name="name">
<input type="submit" name="send">
</form>
<?php
if(isset($_POST['send']))
{
$name = $_POST['name'];
for($=1;$i<2;$++)
{
$name = array($name);
$names = array_push($names,$name);
}
print_r($names);
}
?>`
Does anyone have a better way?
答
I prefer to create indexes after its declaration:
$test = array();
$test['a'] = 'value';
$test['b'] = 'value';
$test['c'] = 'value';