dongxia9620 2013-09-05 14:11
浏览 46
已采纳

如何在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?

  • 写回答

1条回答 默认 最新

  • donglu9896 2013-09-05 14:23
    关注

    I prefer to create indexes after its declaration:

    $test = array();
    $test['a'] = 'value';
    $test['b'] = 'value';
    $test['c'] = 'value';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?