return group_concat data as array

If you need to do it on the MySQL level, and then you may probably parse it to an object. You can do the following

SELECT CONCAT("[", GROUP_CONCAT(category.name), "]") AS categories
From categories

As I said in my comment: you need to explode the data into an array, using php code like this:

$holds = explode(',', $holds);

because mysql has no concept of array-type for data.


This is possible since MySQL 5.7.22 using the JSON_ARRAYAGG() method

Read more: https://dev.mysql.com/doc/refman/5.7/en/aggregate-functions.html#function_json-arrayagg

Example:

SELECT JSON_ARRAYAGG(category.slug) as categories From categories

MySQL has no concept of arrays. Therefore it is not able to return an array. It is up to your processing code (here the php scripts) to convert the concatenated notation into a php array.

Tags:

Mysql

Php