0

I am usign Symfony 3 with Doctrine for get data from db, after get the data, it send to client for add to datatable.

For use the data in the datatable I need a array as follow:

[
 {"id":1
 "app": "stack"},
 {"id":2
 "app": "reddit"}
]

But when I do the query as follow:

  $qb = $this->getEntityManager()->createQueryBuilder();

        return $qb = $qb->select('a')
        ->from('AppsBundle:App', 'a')
        ->orderBy('a.'.$columnOrder, $order)
        ->setFirstResult($start)
        ->setMaxResults($length)
        ->getQuery()
        ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

I get as "json object arrat" as follow:

{
     "0": {"id":1
     "app": "stack"},
     "1": {"id":2
     "app": "reddit"}
    ]

Any idea for get the data as the other representation.

Thanks

1 Answer 1

2

Try with PHP's array_values() function:

$json_out = json_encode(array_values($your_array_here));

Code: Demo

Sign up to request clarification or add additional context in comments.

2 Comments

This work, but now when send data to client, the quotes of the "id" and "app" was changed to \u0022 and datable not recognice the id and app field, any idea?
With array_map I get this error "reset() expects parameter 1 to be array, string given"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.