我有一個包含多個其他數組的數組。這些數組有一個名爲[note]的值,它引用一個名爲$theNote
的變量,它位於數組的上方/外部。這個變量包含一個簡單的模板,只有幾個跨度。PHP - 使用數組之外的值
$theNote = '<span class="icon"></span><span>Hello my name is $thename</span>';
我有一個名爲client_infos
數組,它包含內部像多個陣列
'client_infos' => array (
array (
'name' => 'John smith',
'note' => $theNote,
'prepend' => '',
'append' => '',
'formatting' => 'html',
),
array (
'name' => 'Mary smith',
'note' => $theNote,
'prepend' => '',
'append' => '',
'formatting' => 'html',
),
);
將有數目不詳的名字最終。我需要能夠做的就是在我的模板,調用在一個循環或東西$theNote
及以下將被輸出......
<span class="icon"></span><span>Hello my name is John Smith</span>
正如你所看到的,在陣列使用的【注意事項】信息$theNote
變量,這將輸出一個代碼塊,其中包含一個名爲$thename
的變量。我不知道如何讓我的[姓名]信息進入$thename
變量。
基本上有些如何得到。 $thename
裏面$theNote to = the current array [name] value
。
所有這一切的原因是,我可以輕鬆地更新「筆記」代碼一次,而無需在所有子數組中完成。
我希望我足夠清楚,有什麼想法?
此外,任何幫助實際命名這個問題更好? – bruffstar
所以你想循環通過client_infos輸出每個['名稱']?是嗎? – jan