note 39716 added to function.explode

From: Date: Sun, 08 Feb 2004 16:00:35 +0000
Subject: note 39716 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-64831@lists.php.net to get a copy of this message
I needed a solution to im- and explode associative arrays. Now I use these two functions (there may be a better solution, but it works ;) ): /** **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); }; ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39716 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39716&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39716&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64831) next »