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()
    ; 
0

1 Answer 1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.