1

I want to get only the list of values ​​in the first column of the query.

$types = $em->getRepository('MyBundle:Notice')
    ->createQueryBuilder('n')
    ->select('n.type')
    ->groupBy('n.type')
    ->getQuery()
    ->getResult();
exho json_encode($types);

Result

[{"type":"foo"},{"type":"bar"},{"type":"baz"}]

I want to get a result

["foo","bar","baz"]

Of course, I can manually sort out the data and get the result I needed.

foreach ($types as $key => $type) {
    $types[$key] = $type['type'];
}

But I want to use the standard method, if any. Unfortunately, I did not find such a method in the documentation. Maybe I'm bad looking)

ghost404
  • 299
  • 2
  • 16
  • possible duplicate of [How to get a one-dimensional scalar array as a doctrine dql query result?](http://stackoverflow.com/questions/11657835/how-to-get-a-one-dimensional-scalar-array-as-a-doctrine-dql-query-result) – FuzzyTree Jun 17 '14 at 11:59
  • @FuzzyTree you're right. I wonder if this is the only solution – ghost404 Jun 17 '14 at 13:48
  • I don't think Doctrine allows that, as each item in the first array dimension is a row, not a field. Just as a side note, you could manually do `foreach ($types as &$type) { $type = $type['type']; }` but it's just for fun ;) – Stock Overflaw Jun 18 '14 at 16:19

0 Answers0