note 39716 deleted from function.explode by bjori

From: Date: Mon, 25 Sep 2006 08:12:53 +0000
Subject: note 39716 deleted from function.explode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117604@lists.php.net to get a copy of this message
Note Submitter: hhabermann at pc-kiel dot de ---- I needed a solution to implode and explode associative arrays. Now I use these two functions (there may be a better solution, but it works ;) ): <?php /** * @name implodeAssoc($glue,$arr) * @description makes a string from an assiciative array * @parameter glue: the string to glue the parts of the array with * @parameter arr: array to implode */ function implodeAssoc($glue,$arr) { $keys=array_keys($arr); $values=array_values($arr); return(implode($glue,$keys).$glue.implode($glue,$values)); }; /** * @name explodeAssoc($glue,$arr) * @description makes an assiciative array from a string * @parameter glue: the string to glue the parts of the array with * @parameter arr: array to explode */ function explodeAssoc($glue,$str) { $arr=explode($glue,$str); $size=count($arr); for ($i=0; $i < $size/2; $i++) $out[$arr[$i]]=$arr[$i+($size/2)]; return($out); }; ?>

« previous php.notes (#117604) next »