note 44911 deleted from ref.pgsql by tomsommer

From: Date: Thu, 19 Aug 2004 22:09:35 +0000
Subject: note 44911 deleted from ref.pgsql by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74960@lists.php.net to get a copy of this message
Note Submitter: phill at kenoyer dot com ---- 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}}')); ?>

« previous php.notes (#74960) next »