2 回答

TA貢獻1826條經驗 獲得超6個贊
您想根據 Posted 輸入值創建一個數組嗎?只需將 foreach 循環與$_POST變量一起使用
<?php
if (isset($_POST)) {
foreach ($_POST as $key => $value) { // for every post value
$array[] = array( // we create a array based on the name and the value
$key => $value
);
}
var_dump($array); // dump the array
}
?>
<form method="POST">
<input type="text" name="job title" value="xyz">
<input type="text" name="start date" value="xyz">
<input type="text" name="send date" value="xyz">
<!-- any other input -->
<button type="submit">sd</button>
</form>
該var_dump($array)會給你
array(2) { ["job_title"]=> string(3) "xyz" ["start_date"]=> string(3) "xyz" } array(1) { ["send_date"]=> string(3) "xyz" }
要從數組創建 JSON,只需執行
echo json_encode($array)
- 2 回答
- 0 關注
- 200 瀏覽
添加回答
舉報