note 102774 added to function.implode

From: Date: Sat, 05 Mar 2011 13:26:55 +0000
Subject: note 102774 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-177578@lists.php.net to get a copy of this message
Here is an example how to convert php array to postgresql anyarray type: <?php /** * @author Przemysław Czekaj <xcojack@gmail.com> * @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

« previous php.notes (#177578) next »