配列 php のキーの名前を変更する必要があります: キー名をこの menu_link_content サブ配列に変更する必要があります:
Array
(
[0] => Array
(
[menu_link_id] => 1
[menu_id] => 2
[parent_id] => 0
[page_id] => 1
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:16
[page_path] =>
[menu_link_content] => Array
(
[0] => Array
(
[menu_link_content_id] => 1
[menu_link_id] => 1
[lang_id] => 1
[menu_link_text] => home
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
[1] => Array
(
[menu_link_content_id] => 3
[menu_link_id] => 1
[lang_id] => 3
[menu_link_text] => home inglese
[menu_link_title] =>
[lang_flag] => inghilterra.jpg
[lang_name] => Inglese
)
)
)
[1] => Array
(
[menu_link_id] => 2
[menu_id] => 2
[parent_id] => 0
[page_id] => 2
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:19
[page_path] =>
[menu_link_content] => Array
(
[0] => Array
(
[menu_link_content_id] => 2
[menu_link_id] => 2
[lang_id] => 1
[menu_link_text] => prova
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
)
)
)
私はこの結果を望んでいます:
Array
(
[0] => Array
(
[menu_link_id] => 1
[menu_id] => 2
[parent_id] => 0
[page_id] => 1
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:16
[page_path] =>
[menu_link_content] => Array
(
[this_lang_id in this case is 1] => Array
(
[menu_link_content_id] => 1
[menu_link_id] => 1
[lang_id] => 1
[menu_link_text] => home
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
[this_lang_id in this case is 3] => Array
(
[menu_link_content_id] => 3
[menu_link_id] => 1
[lang_id] => 3
[menu_link_text] => home inglese
[menu_link_title] =>
[lang_flag] => inghilterra.jpg
[lang_name] => Inglese
)
)
)
[1] => Array
(
[menu_link_id] => 2
[menu_id] => 2
[parent_id] => 0
[page_id] => 2
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:19
[page_path] =>
[menu_link_content] => Array
(
[this_lang_id in this case is 1] => Array
(
[menu_link_content_id] => 2
[menu_link_id] => 2
[lang_id] => 1
[menu_link_text] => prova
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
)
)
)
次に、この [menu_link_content] [0] は必要ありませんが、この [menu_link_content] [1] が必要です。これは、その [menu_link_content] 配列に含まれる lang_id であるためです。
どうすればいいですか?
mod これは私の機能です:
$this->query('
SELECT c.*, l.lang_flag, l.lang_name
FROM tb_menu_link_content AS c
INNER JOIN tb_lang AS l
ON l.lang_id = c.lang_id
WHERE c.menu_link_id = "'.$menu_link['menu_link_id'].'"
');
$menu_link_content = $this->fetch_assoc_all();
foreach($menu_link_content as $key => $value){
$lang_id = $value['lang_id'];
$new_array[$lang_id] = $value;
}
$menu_link_content = array('menu_link_content'=>$new_array);
$array[] = array_merge($menu_link, $menu_link_content);
うまく機能しますが、2 番目のサブ配列 [menu_link_content] にある言語と重複します lang_id 3 は 2 番目の [menu_link_content] に存在しません
Array
(
[0] => Array
(
[menu_link_id] => 1
[menu_id] => 2
[parent_id] => 0
[page_id] => 1
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:16
[page_path] =>
[menu_link_content] => Array
(
[1] => Array
(
[menu_link_content_id] => 1
[menu_link_id] => 1
[lang_id] => 1
[menu_link_text] => home
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
[3] => Array
(
[menu_link_content_id] => 3
[menu_link_id] => 1
[lang_id] => 3
[menu_link_text] => home inglese
[menu_link_title] =>
[lang_flag] => inghilterra.jpg
[lang_name] => Inglese
)
)
)
[1] => Array
(
[menu_link_id] => 2
[menu_id] => 2
[parent_id] => 0
[page_id] => 2
[menu_link_type] => page
[menu_link_order] =>
[menu_link_url] =>
[menu_link_class] =>
[menu_link_date] => 2013-10-08 14:23:19
[page_path] =>
[menu_link_content] => Array
(
[1] => Array
(
[menu_link_content_id] => 2
[menu_link_id] => 2
[lang_id] => 1
[menu_link_text] => prova
[menu_link_title] =>
[lang_flag] => italia.jpg
[lang_name] => Italiano
)
[3] => Array
(
[menu_link_content_id] => 3
[menu_link_id] => 1
[lang_id] => 3
[menu_link_text] => home inglese
[menu_link_title] =>
[lang_flag] => inghilterra.jpg
[lang_name] => Inglese
)
)
)
)
私の問題はこれです:私はこの配列$メニューを持っていて、配列$言語を持っています
見つかった言語ごとに作成する関数を作成する必要があります。
<input type="text" name="menu_link_text[$language['lang_id']]" value="$menu['menu_link_text'][$language['lang_id']">