問題
フラットスカラー値から入力する必要があるネストされたPHP配列があります。問題は、フラットなスカラー値を入力する要求を受け取るまで、ネストされたPHP配列の構造がどうなるかを事前に知ることができないことです。
例
// example where we populate the array using standard PHP
$person['contact_info']['fname'] = 'Attilla';
$person['contact_info']['lname'] = 'Hun';
$person['contact_info']['middle'] = 'The';
$person['hobbies'][0] = 'Looting';
$person['hobbies'][1] = 'Pillaging';
// example where we populate the array from flat scalar values
// (these are obtained from the user via name-value pairs)
// how can I correctly populate $person from this??
print($_GET['contact_info.fname']); // 'Smokey';
print($_GET['contact_info.middle']); // 'The';
print($_GET['contact_info.lname']); // 'Bear';
// how can I correctly populate $person from this??
print($_GET['contact_info.fname']); // 'Jabba';
print($_GET['contact_info.middle']); // 'The';
print($_GET['contact_info.lname']); // 'Hutt';
// How can I use these three flat scalars
// to populate the correct slots in the nested array?
質問
私は、フラットな名前と値のペアからネストされたPHP配列(または任意のプログラミング言語のネストされた配列)に変換する必要がある最初の人であってはならないことを知っています。これらのフラットなスカラーの名前と値のペアを適切なPHPネスト配列に変換する確立された方法(ある場合)は何ですか?
繰り返しになりますが、配列にデータを入力するための名前と値のペアが何になるかを前もって知ることはできません。これは、ここで扱っている制約の1つです。
アップデート
値(または、必要に応じて、スカラー値表現によって入力される配列キー)を知ることができないという事実は、私が扱っている特定の問題空間の制約です。これは、基本的なPHP配列構文に関する質問ではありません。