It is necessary on an output from echo json_encode($array); get this json format:

 var currencies = [ { id: '1', name: 'Paris' }, { id: '2', name: 'London' } ]; 

The array $ array is the result from the query to the database for a sample of 2 id and name fields.

    1 answer 1

    In order for json_encode($array) return the result in the required form, the incoming data must be in this format

     array( array( 'id' => '1', 'name' => 'Paris' ), array( 'id' => '2', 'name' => 'London' ) )