这必须是更好的方法吗?我想从声音集合中获取所有文档,并将它们与包含对象的数组一起输出(将其用于主干.js)。它不能是一个有物体的物体!
$sounds = iterator_to_array($db->sounds->find());
$a = "[";
foreach ($sounds as $id => $sound) {
$a .= json_encode($sound) . ",";
}
//remove the last comma...
$a = substr($a, 0, -1);
$a .="]";
echo $a;