note 12304 deleted from function.implode by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 22:27:10 +0000 |
| Subject: | note 12304 deleted from function.implode by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23499@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