2014-10-28 44 views
-3

我想打印使用數組的表單字段的值。我在file1.php中有兩個字段,名稱電子郵件,我通過post傳遞給file2.php並將其存儲在數組中。如何在PHP的表單字段中打印數組值?

<?php 
    $name = $_post['name'] 
    $email = $_post['email]; 
    function personal($name, $email) { 
     $return = array($name, $email); 
     print_r($return); //Output(Array ([0] => alisha [1] => [email protected]) 
     echo implode('<br>', $return); //Output alisha  [email protected] 

?> 

如何打印這些值,ALISHA[email protected],在file1.php當用戶使用提交按鈕轉到上一頁而不使用會話和餅乾?

<input type=text name=name value="**print alisha here array[0]**"> 
<input type=text name=email value="**print [email protected] here array[1]**"> 
+2

value =「<?php echo $ return [0]?>」,但我不明白爲什麼你應該使用數組,當你有變量allready($ name,$ email))? – bksi 2014-10-28 23:18:47

+0

@bksi - 也將它們作爲$ _POST ['email']&$ _POST ['name']。爲什麼他們經歷了兩次相同值的變化? – ggdx 2014-10-28 23:25:46

+0

@bksi -its,因爲我使用隱藏變量和函數將此變量傳遞給多個頁面,並最終將所有值存儲在數組中。沒有數組我能夠解決這個問題。 – user3385022 2014-10-28 23:40:56

回答

0
<input type="text" name="name" value="<?= $return[0]; ?>" /> 

<input type="text" name="email" value="<?= $return[1]; ?>" /> 

你只需要呼應陣列鍵(0名,1用於電子郵件)。

+0

我試過了'Name:」>
'但它不起作用 – user3385022 2014-10-28 23:42:41

+0

您有任何錯誤信息? – ggdx 2014-10-29 12:47:55

+1

user3385022,你需要顯示更多的代碼 – bksi 2014-10-29 17:43:51