0

I have this weird array output after I execute a query and it looks like this

array:32 [▼
  0 => array:1 [▼
    "key" => "overview.domain"
  ]
  1 => array:1 [▼
    "key" => "overview.msg_latest_translation"
  ]
  2 => array:1 [▼
    "key" => "overview.no_stats"
  ]

But all i want it to be only one array, not a nested array. SO it would look something like this

array:32 [▼
  "overview.domain",
  "overview.msg_latest_translation",
  "overview.no_stats"
]

What would be the best way to solve this ?

This is the query that i am executing, which is giving me the first output:

  return $this->createQueryBuilder('t')
        ->select('t.key')
        ->getQuery()
        ->getResult()
    ; 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

Use this (PHP array_map):

$rows = $this->createQueryBuilder('t')
        ->select('t.key')
        ->getQuery()
        ->getResult();
    
$arr = array_map(function($_v){return $_v['key'];}, $rows);

With array_map you can change the values of the array by its value.

Sina Kadkhodaei
  • 510
  • 4
  • 10