次のような配列があります。
Array
(
[0] => Array
(
[insert_input_id] => 1
[action_id] => 1
[table] => users
[name] => nickname
[parent] => nickname
[owner] =>
)
[1] => Array
(
[insert_input_id] => 2
[action_id] => 1
[table] => users
[name] => email
[parent] => email
[owner] =>
)
[2] => Array
(
[insert_input_id] => 3
[action_id] => 1
[table] => users
[name] => name
[parent] => name
[owner] =>
)
[3] => Array
(
[insert_input_id] => 4
[action_id] => 1
[table] => users
[name] => surname
[parent] => surname
[owner] =>
)
[4] => Array
(
[insert_input_id] => 5
[action_id] => 1
[table] => social
[name] => social_id
[parent] => social_id
[owner] => user_id
)
[5] => Array
(
[insert_input_id] => 6
[action_id] => 1
[table] => social
[name] => social_token
[parent] => social_token
[owner] => user_id
)
[6] => Array
(
[insert_input_id] => 7
[action_id] => 1
[table] => social
[name] => social_type
[parent] => social_type
[owner] => user_id
)
)
上記の配列からわかるように、同じ[table]
値を持つものもあります。この特定のケースでは、 と が[table] => social
あり[table] => users
ます。そのため、同じテーブルに基づいて配列をリファクタリングし、次の結果を達成しようとしています。
Array
(
[users] => Array
(
[owner] =>
[nickname] => giorgio
[email] => giorgia@m.com
[name] => giorgia
[surname] => giorgio
)
[social] => Array
(
[owner] => user_id
[social_id] => 23123
[social_token] =>
[social_type] => facebook
)
)
これは私がPHPコードでやっていることです:
foreach ($inserts as $insert) {
if (isset($data[$insert['parent']])) {
$vals['owner'] = $insert['owner'];
$vals[$insert['name']] = $data[$insert['parent']];
$tables[$insert['table']] = $vals;
}
}
echo '<pre>'; print_r($tables); echo '</pre>';
$data
$_GET
or$_POST
リクエストによって与えられたデータです。
正しい を割り当てることに関しては、すべて問題ありません$data
。問題は、次の配列を取得していることです。
Array
(
[users] => Array
(
[owner] =>
[nickname] => giorgio
[email] => giorgia@m.com
[name] => giorgia
[surname] => giorgio
)
[social] => Array
(
[owner] => user_id
[nickname] => giorgio
[email] => giorgia@m.com
[name] => giorgia
[surname] => giorgio
[social_id] => 23123
[social_token] =>
[social_type] => facebook
)
)
ご覧のとおり、[social]
配列には配列の要素も含まれていますが[users]
、これは間違っています。
どうすればこれを回避できますか?
なにか提案を?