mardi 5 mai 2015

How to return an array instead of object in JSON response?

I've one working REST API developed using Slim PHP framework.

It's working absolutely fine.

The only issue is when there is no error present i.e. an array $errors is empty it comes as an array in JSON response but when the array $errors contains any error like $errors['user_name'] then it comes as an object in JSON response.

Actually I want to return the array when error is present. How should I do this? Can someone please help me in this regard?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire