我無法找到任何答案,因此我目前沒有任何想法。手動將元素添加到提取數組的末尾
我有以下環路由陣列中的存儲,數據庫的資源獲取
$posts = array();
while ($row = mysql_fetch_assoc($result)){
$posts[] = $row;
}
return $posts;
上$posts
var_dump
輸出以下:
array (size=1)
0 =>
array (size=6)
0 =>
array (size=4)
'items' => string '16' (length=2)
'item_name' => string 'Blu-ray Disc Player BDP-S1100' (length=29)
'item_price' => string '3500.00' (length=7)
'avatar' => string 'gallery/miniaturas/cf6772a2c2b72d575f11b41aee5a2f47.png' (length=55)
1 =>
array (size=4)
'items' => string '16' (length=2)
'item_name' => string 'Blu-ray Disc Player BDP-S1100' (length=29)
'item_price' => string '3500.00' (length=7)
'avatar' => string 'gallery/miniaturas/a6bf82f38d930567a759eaef91d6fb30.png' (length=55)
我想什麼做的是在每個陣列的末尾添加一個帶有「type」鍵值和「1」的靜態值,因此var_dump
將如下所示:
array (size=1)
0 =>
array (size=6)
0 =>
array (size=4)
'items' => string '16' (length=2)
'item_name' => string 'Blu-ray Disc Player BDP-S1100' (length=29)
'item_price' => string '3500.00' (length=7)
'avatar' => string 'gallery/miniaturas/cf6772a2c2b72d575f11b41aee5a2f47.png'
'type' => int 1
(length=55)
1 =>
array (size=4)
'items' => string '16' (length=2)
'item_name' => string 'Blu-ray Disc Player BDP-S1100' (length=29)
'item_price' => string '3500.00' (length=7)
'avatar' => string 'gallery/miniaturas/a6bf82f38d930567a759eaef91d6fb30.png'
'type' => int 1
(length=55)
可能嗎?如果是這樣,怎麼樣?
謝謝。
這工作得很好!非常感謝 – DannyG