note 44911 added to ref.pgsql
| From: | phill at kenoyer dot com | Date: | Thu, 19 Aug 2004 22:03:11 +0000 |
| Subject: | note 44911 added to ref.pgsql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74958@lists.php.net to get a copy of this message | ||
Here is my version of PG Array to PHP Array. I just whipped it up, so there may be a few bugs in
it. So far I haven't found anything wrong. It does single and multi-dimensional arrays.
<?php
function pgtophp($pg_array = FALSE, $dimension = 0)
{
if (!$pg_array) return (FALSE);
$array = array();
$level = 0;
$begin = 1;
if (!strstr($pg_array, '{') and !strstr($pg_array, '}'))
{
$array = explode(',', $pg_array);
return ($array);
}
for ($count = 0; $count < strlen($pg_array); $count++)
{
if ($pg_array[$count] == '{') { $level++; }
elseif ($pg_array[$count] == '}') { $level--; }
if ($level == 1 and $pg_array[$count] == '{') { $begin = $count; }
if ($level == 0 and $pg_array[$begin] == '{')
{
$array[] = pgtophp(substr($pg_array, $begin + 1, $count - $begin - 1), $dimension + 1);
$begin = $count;
}
}
if ($dimension == 0)
{
$array = $array[0];
}
return ($array);
}
print_r (pgtophp('{{test1,100},{test2,100}}'));
?>
----
Manual Page -- http://www.php.net/manual/en/ref.pgsql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44911
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44911&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44911&report=yes
Search -- http://master.php.net/manage/user-notes.php