2013-09-05 42 views
0

數組我想新的數據添加到一個數組如何使用動態HTML和PHP添加數據動態到PHP

這裏是我的代碼:

<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); 
    } 
    ?>` 

有沒有人有更好的辦法?

+0

因爲一旦被要求在執行你的腳本,它被執行後,所有數據將被破壞。要在多個請求之間存儲數據,請使用[sessions](http://php.net/manual/en/features.sessions.php)。 –

回答

0

我更喜歡它的聲明後創建索引:

$test = array(); 
$test['a'] = 'value'; 
$test['b'] = 'value'; 
$test['c'] = 'value';