note 87435 deleted from ref.array by danbrown
| From: | danbrown@php.net | Date: | Fri, 05 Dec 2008 03:29:13 +0000 |
| Subject: | note 87435 deleted from ref.array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147658@lists.php.net to get a copy of this message | ||
Note Submitter: cristiano at galvao dot pro dot br
Reason: bad code
----
Hi. I use this function to convert an array into a string, using an optional separator.
It can converted back to array (flat array) using the standard PHP split function.
<?php
/*
* Hi! I use this function to convert an array into a string.
* Note that to convert back into array (flat array), we can use standard PHP split function.
* Here is:
*/
/*--- Function ARRAY TO STRING ---
*
* Description: Turns an array into a concatenated string
* Arguments: Flat or multidimensional array and optional separator
* Example: array(1,2,3,array('x','yz'),4),"-" --->
"1-2-3-x-yz-4"
*
* Author: Cristiano Galvão
* Contact: cristiano@galvao.pro.br
* About: http://www.galvao.pro.br
*
*/
function array_to_string( $array, $separator = NULL ) {
if( is_array( $array ) ) {
foreach( $array as $element ) {
$string .= array_to_string( $element, $separator ) . $separator;
}
$string = substr( $string, 0, strlen( $string ) - strlen( $separator ) );
} else {
$string = $array;
}
return $string;
}
?>