0
我試圖把數據放入from
:按某個鍵/值到現有陣列
[comments] => Array
(
[count] => 2
[data] => Array
(
[0] => Array
(
[idcomments] => 1
[from] => Array
(
[idusers] => 1
[username] =>
[full_name] => AndrewLiu
)
[text] => testing this comment out
)
[1] => Array
(
[idcomments] => 2
[from] => Array
(
[idusers] => 1
[username] =>
[full_name] => AndrewLiu
)
[text] => more comments yeah
)
)
)
我有這樣的事情:
while($row = $SQL_products -> fetch(PDO::FETCH_ASSOC)){
$json['data'][] = array(
"comments" =>array(
"count"=>$SQL_ccount[0],
"data" => array($SQL_comments->fetchAll(PDO::FETCH_ASSOC),
"from" => array($SQL_comments_from->fetchAll(PDO::FETCH_ASSOC)))
),
);
}
不過,這並不落入from
。不知道正確的語法是讓$SQL_comments_from
進入data
這樣像上面的例子是什麼。
這就是我得到
[comments] => Array
(
[count] => 2
[data] => Array
(
[0] => Array
(
[0] => Array
(
[idcomments] => 1
[from] => 1
[text] => testing this comment out
)
[1] => Array
(
[idcomments] => 2
[from] => 2
[text] => more comments yeah
)
)
[from] => Array
(
[0] => Array
(
[idusers] => 1
[username] =>
[full_name] => AndrewLiu
)
)
)
)
我試圖讓"from"
進入"data"
。我提供的例子不「從」進入其他的「從」做(這就是正確的下idcomments)
提前感謝!
你是什麼意思它混在一起? – hellomello
感謝穆薩,但有另一種方式,而不是正從[0],如果我有什麼多個陣列只需$?就像我匹配id的$是從[0]改爲其他的?謝謝! – hellomello
我認爲,但由於$只有一個項目,我使用'$ from [0]' – Musa