note 38863 deleted from faq by nlopess
| From: | nlopess@php.net | Date: | Sat, 17 Apr 2004 09:11:47 +0000 |
| Subject: | note 38863 deleted from faq by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-68236@lists.php.net to get a copy of this message | ||
Note Submitter: PietroAbbatiMarescotti p.abbati@ieee.org
----
Regarding implode and explode function, they do not allow to save keys as well. Basing on function
wrote by static (14-May-2002 07:43), I wrote these two functions that allow to export and import an
array with its keys:
function implode_with_keys($glue, $keyglue, $array) {
$output = array();
foreach( $array as $key => $item )
$output[] = $key . $keyglue . $item;
return implode($glue, $output);
}
function explode_with_keys($glue, $keyglue, $string) {
$imported_array = array();
$original_array = array();
$imported_array = explode($glue,$string);
foreach($imported_array as $row){
list($key,$value) = explode($keyglue,$row);
$original_array[$key] = $value;}
return $original_array;
}
Obviously, $glue and $keyglue MUST be different, and no one of them should appear in values.
Ciao - PietroAM