我正在重写一份时事通讯。
我有一个包含所有时事通讯字段的表格,如下所示:
field_uid | field_name | field_content | field_letter_id
其中 fx 列field_name
可以有值letter_headline
,列field_content
可以有值My headline
。
当我这样做时:
$fields = $this->db->dbh->query("SELECT field_name, field_content FROM newsletter_fields WHERE field_letter_uid = '". $letter_id ."'");
foreach($fields->fetchAll(PDO::FETCH_ASSOC) as $key) {
print_r($key);
}
它会正确地给我这个:
Array ( [field_name] => letter_image0 [field_content] => image.jpg )
Array ( [field_name] => letter_headline [field_content] => My headline )
Array ( [field_name] => letter_headline_size [field_content] => 12 )
Array ( [field_name] => letter_sub_headline [field_content] => My subheadline )
Array ( [field_name] => letter_sub_headline_size [field_content] => 10 )
Array ( [field_name] => letter_content [field_content] => Letter content )
Array ( [field_name] => letter_link [field_content] => www.example.com )
Array ( [field_name] => letter_link_txt [field_content] => Example )
我想要的是建立一个这样的数组
$field["letter_image"] = "image.jpg";
$field["letter_headline"] = "My headline"
然后我可以输出内容:
echo $field["letter_image"];
但我似乎无法弄清楚如何设置字段数组。