パオロの答えを見て、三項演算子を理解してください。
見ていることを行うには、セッション変数を使用することをお勧めします。
ページの上部にこれを置きます(セッションを開始する前にページに何も出力できないためです.IE NO ECHO STATEMENTS)
session_start();
次に、ユーザーがフォームを送信したら、結果をこのサーバー変数に保存します。ユーザーがフォームを送信したのが初めての場合は、直接保存するか、循環して空でない値を追加します。これがあなたが探しているものかどうかを確認してください:
HTML コード (testform.html):
<html>
<body>
<form name="someForm" action="process.php" method="POST">
<input name="items[]" type="text">
<input name="items[]" type="text">
<input name="items[]" type="text">
<input type="submit">
</form>
</body>
</html>
処理コード (process.php):
<?php
session_start();
if(!$_SESSION['items']) {
// If this is the first time the user submitted the form,
// set what they put in to the master list which is $_SESSION['items'].
$_SESSION['items'] = $_POST['items'];
}
else {
// If the user has submitted items before...
// Then we want to replace any fields they changed with the changed value
// and leave the blank ones with what they previously gave us.
foreach ($_POST['items'] as $key => $value) {
if ($value != '') { // So long as the field is not blank
$_SESSION['items'][$key] = $value;
}
}
}
// Displaying the array.
foreach ($_SESSION['items'] as $k => $v) {
echo $v,'<br>';
}
?>