PHP 8.5.0 Alpha 4 available for testing

Voting

: three minus two?
(Example: nine)

The Note You're Voting On

1413 at blargh dot com
19 years ago
Here is some quick and dirty code to convert Postgres-returned arrays into PHP arrays. There's probably a billion bugs, but since I'm only dealing with variable-depth-and-length arrays of integers, it works for my needs.

Most notably, any data that might have commas in it won't work right...

<?php
function PGArrayToPHPArray($pgArray)
{
$ret = array();
$stack = array(&$ret);
$pgArray = substr($pgArray, 1, -1);
$pgElements = explode(",", $pgArray);

ArrayDump($pgElements);

foreach(
$pgElements as $elem)
{
if(
substr($elem,-1) == "}")
{
$elem = substr($elem,0,-1);
$newSub = array();
while(
substr($elem,0,1) != "{")
{
$newSub[] = $elem;
$elem = array_pop($ret);
}
$newSub[] = substr($elem,1);
$ret[] = array_reverse($newSub);
}
else
$ret[] = $elem;
}
return
$ret;
}
?>

<< Back to user notes page

To Top