note 102774 added to function.implode

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Here is an example how to convert php array to postgresql anyarray type:

<?php
/**
 * @author Przemysław Czekaj <[email protected]>
 * @link http://www.cojack.pl
 */
function phpArrayToPg(array $phpArray, $inner_glue = ',') {
   foreach($phpArray as $key => $value) {
      if(is_array($value)) {
         $output[$key] = "{".phpArrayToPg($value, $inner_glue)."}";
      }
      else {
         if(!(int)$value)
            $output[$key] = '"'.$value.'"';
         else
            $output[$key] = (int)$value;
      }
   }

   return implode($inner_glue,$output);
}
?>

Usage?

Some array:

<?php
$a = array(
   array(
      1,
      'cgusia',
   ),
   array(
      6,
      2
   ),
   array(
      'oruflik',
      'jrzmiot'
   )
);

echo "E'{".phpArrayToPg($a)."}'";
?>

the above example will output:

E'{{1,"cgusia"},{6,2},{"oruflik","jrzmiot"}}'

How you will secure this part of data when you will send them to the sql server it's only your problem.

Cast them and it works awesome ;)
----
Server IP: 69.147.83.197
Probable Submitter: 89.73.67.156
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit        -- https://master.php.net/note/edit/102774
Del: integrated  -- https://master.php.net/note/delete/102774/integrated
Del: useless     -- https://master.php.net/note/delete/102774/useless
Del: bad code    -- https://master.php.net/note/delete/102774/bad+code
Del: spam        -- https://master.php.net/note/delete/102774/spam
Del: non-english -- https://master.php.net/note/delete/102774/non-english
Del: in docs     -- https://master.php.net/note/delete/102774/in+docs
Del: other reasons-- https://master.php.net/note/delete/102774
Reject      -- https://master.php.net/note/reject/102774
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.