note 38863 added to faq

From: Date: Fri, 09 Jan 2004 11:16:45 +0000
Subject: note 38863 added to faq
Groups: php.notes 
Request: Send a blank email to php-notes+get-63193@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/faq.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38863 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38863&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38863&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63193) next »