php - from mongodb to array with objects -
it must better way this? want documents sounds collection , output them array objects in (using backbone.js). it cant object objects in!
$sounds = iterator_to_array($db->sounds->find()); $a = "["; foreach ($sounds $id => $sound) { $a .= json_encode($sound) . ","; } //remove last comma... $a = substr($a, 0, -1); $a .="]"; echo $a;
you try:
$sounds = iterator_to_array($db->sounds->find()); echo json_encode(array_values($sounds));
array_values
return values of associated array indexed array json_encode
return json encoded string in format want (i.e. javascript array instead of javascript object).
Comments
Post a Comment