note 12304 modified in function.implode.php by zak
| From: | zak@php.net | Date: | Thu, 19 Jul 2001 19:57:51 +0000 |
| Subject: | note 12304 modified in function.implode.php by zak | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15600@lists.php.net to get a copy of this message | ||
[Editor's Note:
The serialize() function provides a robust way
to store associative arrays for later use.
--zak@php.net]
This function stores associative arrays the same as a non-associative. This can be a problem store
an array as a string with the ability to bring the array back at a later time (example: caching or
storing an array in a database). To handle associative arrays, I've devised this simple
function: associative_implode( )
######
## Begin Code
function associative_implode( $glue, $array ) {
reset( $array );
$return_str = '';
while( list( $n, $v ) = each( $array ) ) {
$return_str .= $n . '=' . $v . $glue;
}
return substr( $return_str, 0, -( strlen( $glue ) ) );
}
######
## End Code
http://www.php.net/manual/en/function.implode.php.php