Skip to content
Advertisement

Issue generating proper JSON array response

Essentially I have the following PHP script that generates a response based on output of the query, I need the JSON to in a different format with each response listed sequentially:

JavaScript

The current response look like this:

JavaScript

The response I am looking for:

JavaScript

How can this be achieved?’

UPDATE: Calling: $response['reasons'] = $row; Get the following result:

JavaScript

How can I get the sequential numbers to appear before the each row result?

JavaScript

Advertisement

Answer

If you need the indexes to start from 1 instead of 0, you need to write a loop that assigns the keys.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement