note 107047 deleted from ref.pgsql by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 Jan 2012 21:45:28 +0000 |
| Subject: | note 107047 deleted from ref.pgsql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185282@lists.php.net to get a copy of this message | ||
Note Submitter: char101 at ui dot ac dot id
----
Yet another function to convert 1D postgresql array string to PHP array using str_getcsv
/**
* @param string $str postgresql array string
* @param string $type int2|int4|int8|varchar|char|text|bool
*/
function decode_postgres_array($str, $type)
{
$arr = str_getcsv(substr($str, 1, -1));
$ret = array();
switch ($type) {
case 'bool':
foreach ($arr as $val) {
$ret[] = $val === 't' ? true : false;
}
break;
case 'text':
case 'varchar':
case 'char':
foreach ($arr as $val) {
$ret[] = stripcslashes($val);
}
break;
default:
$ret = $arr;
}
return $ret;
}