0
我使用PHP完成了MySQL查詢,結果以數組形式呈現。剝離PHP陣列的JSON編碼
$stmt = $mysqli->prepare("SELECT word FROM words ORDER BY RAND() LIMIT 5");
$stmt->bind_result($words);
$stmt->execute();
$result = array();
while ($stmt->fetch()) {
$w = new StdClass();
$w->word = $words;
array_push($result, $w);
}
$stmt->close();
然後,我使用JSON傳遞數組的JavaScript:
'words' : <?php echo json_encode($result); ?>,
但輸出是:
[{"word":"Watermelon"},{"word":"Orange"},{"word":"Melon"},{"word":"Cucumber"},{"word":"Apple"}]
是否有任何方式爲 「條」 之「字「並讓它看起來像那樣?
["Watermelon", "Orange", "Melon", "Cucumber", "Apple"]
在此先感謝您。
謝謝!顯然我過於複雜的東西:) –
如果答案有幫助 - 隨時接受它,作爲您以前的問題的答案。它可以幫助你和回答者) –