配列スタイルの名前で投稿されたフォーム入力があるとします:
<input type="text" name="user[name]" value="John" />
<input type="text" name="user[email]" value="foo@example.org" />
<input type="checkbox" name="user[prefs][]" value="1" checked="checked" />
<input type="checkbox" name="user[prefs][]" value="2" checked="checked" />
<input type="text" name="other[example][var]" value="foo" />
その後$_POST
、次のように返されますprint_r()
。
Array
(
[user] => Array
(
[name] => John
[email] => foo@example.org
[prefs] => Array
(
[0] => 1
[1] => 2
)
)
[other] => Array
(
[example] => Array
(
[var] => foo
)
)
)
目標は、次のように関数を呼び出せるようにすることです。
$form_values = form_values($_POST);
これは、元の入力名のスタイルに似たキーを持つ連想配列を返します。
Array
(
[user[name]] => John
[user[email]] => foo@example.org
[user[prefs][]] => Array
(
[0] => 1
[1] => 2
)
[other[example][var]] => foo
)
これは非常に困難であり、この時点で私の「車輪は泥の中で回転しています」。:-[