PHP array to postgres array -


now php can't work directly wit postgresql array. example, php taking postgresql array '{"foo","bar"}'

i need simple php function create multidimensional postgresql array php array.

i think experimental pg_convert() isn't optimal because needs of data form simple array string database output, maybe misunderstood idea of function.

for example, need convert

$from=array(  array( "par_1_1","par_1_2" ), array( "array_2_1", "array_2_2" )  ); $to='{{"par_1_1","par_1_2"},{"par_2_1","par_2_2"}}'; 

can use array_walk_recursive() convert deepest elements of array?

here's simple function converting php array pg array.

function to_pg_array($set) {     settype($set, 'array'); // can called scalar or array     $result = array();     foreach ($set $t) {         if (is_array($t)) {             $result[] = to_pg_array($t);         } else {             $t = str_replace('"', '\\"', $t); // escape double quote             if (! is_numeric($t)) // quote non-numeric values                 $t = '"' . $t . '"';             $result[] = $t;         }     }     return '{' . implode(",", $result) . '}'; // format } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -