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

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -