Question: I have trouble reading Postgresql arrays in PHP. I have tried explode(), but this breaks arrays containing commas in strings, and `str_getcsv()` but it's also no good as PostgreSQL doesn't quote the Japanese strings.

Not working:

```
explode(',', trim($pgArray['key'], '{}'));
str_getcsv( trim($pgArray['key'], '{}') );

```

Example:

```
// print_r() on PostgreSQL returned data: Array ( [strings] => {または, "some string without a comma", "a string, with a comma"} )

// Output: Array ( [0] => または [1] => "some string without a comma" [2] => "a string [3] => with a comma" ) 
explode(',', trim($pgArray['strings'], '{}'));

// Output: Array ( [0] => [1] => some string without a comma [2] => a string, with a comma ) 
print_r(str_getcsv( trim($pgArray['strings'], '{}') ));

```

Answer: 
If you can foresee what kind text data you can expect in this field, you can use `array_to_string` function. It's available in 9.1

E.g. I exactly know that my array field `labes` will never have symbol `'\n'`. So I convert array `labes` into string using function `array_to_string`

```
SELECT 
  ...
  array_to_string( labels, chr(10) ) as labes
FROM
  ...

```

Now I can split this string using PHP function `explode`:

```
$phpLabels = explode( $pgLabes, "\n" );

```

You can use any sequence of characters to separate elements of array.

SQL:

```
SELECT
  array_to_string( labels, '<--###DELIMITER###-->' ) as labes

```

PHP:

```
$phpLabels = explode( '<--###DELIMITER###-->', $pgLabes );

```
If you have control of the query that's hitting the database, why don't you just use [`unnest()`](https://www.postgresql.org/docs/current/static/functions-array.html) to get the results as rows instead of Postgres-arrays? From there, you can natively get a PHP-array.

```php
$result = pg_query('SELECT unnest(myArrayColumn) FROM someTable;');
if ( $result === false ) {
    throw new Exception("Something went wrong.");
}
$array = pg_fetch_all($result);

```

This sidesteps the overhead and maintenance-issues you'd incur by trying to convert the array's string-representation yourself.