如何添加數組到數組項目?如何添加一個新的數組到一個項目?
我希望每個項目有一個數組分配給它,在這種情況下與tags
鍵。但隨着預期的下面不工作:
<?php
function getNews() {
$sql = "SELECT * FROM news WHERE active = '1' AND deleted='0'
ORDER BY date_posted DESC LIMIT ".
(isset($settings['news_limit_index'])
? $settings['news_limit_index'] : '4');
$result = $this->db->query($sql);
while($data=$result->fetch_assoc()){
$r_news[] = $data;
$r_news[]['tags'] = array('one','two','three'); // hardcoded for testing!
}
return $r_news;
}
?>
的[?用PHP陣列中添加項目到數組(HTTP可能重複:// stackoverflow.com/questions/12679617/adding-items-to-an-array-within-an-array-with-php) – JoeG