I create a multidimensional array, so there is one statement arraythat wraps the others.
I create a second arrayinternal one that has the keys and values of: date, gloss, expense_no_dducible, prefix and details
To form the group of values, which are linked to the details key , we do this: detalles: array(....., so that the value of said key will be a collection of records, the 4 groups that it has inside.
Lastly you can use the PHP constant called JSON_UNESCAPED_SLASHESwhich will prevent escaping slashes.
In addition to the above.
Optional
I also use JSON_PRETTY_PRINTto be able to get the result in an indented way and similar to your image, it is important to remember to separate the 2 previous constants by the | symbol. although this constant is not strictly necessary
Try to do it this way, it's an example:
Which gives me this result:
Explanation
array
that wraps the others.array
internal one that has the keys and values of: date, gloss, expense_no_dducible, prefix and detailsdetalles: array(.....
, so that the value of said key will be a collection of records, the 4 groups that it has inside.your exercise
Resulting:
Necessary
In addition to the above.
Optional
The only thing you have to do is put little ones
array
inside aarray
main, when doingjson_encode
it they will become a singlearray
object:You would have to create an array of arrays for the missing element, something like this: