note 81215 added to function.implode
| From: | Anonymous at osu1 dot php dot net | Date: | Mon, 18 Feb 2008 23:41:30 +0000 |
| Subject: | note 81215 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136259@lists.php.net to get a copy of this message | ||
So I looked through all the problem solutions posted here, and combined them into one nice
recursive function.
<?php
function implode_md( $glue, $array, $key = NULL, $list = NULL )
{
if( !is_array( $array ) )
return $array;
if( !sizeof( $array ) )
return "";
if( !is_null( $key ) )
{
if( strpos( $key, "." ) )
{
$keys = array_reverse( explode( ".", $key ) );
$currentKey = array_pop( $keys );
if( sizeof( $keys ) ) $keys = implode( ".", $keys );
else $keys = implode( "", $keys );
}
else
{
$currentKey = $key;
$keys = NULL;
}
if( array_key_exists( $currentKey, $array ) )
return implode_md( $glue, $array[$currentKey], $keys, $list );
else
return "";
}
if( !empty( $list ) )
{
$last = array_pop( $array );
if( count( $array ) )
return implode_md( $glue, $array, $key ) . " $list $last";
else
return $last;
}
$ret = array();
for( $i = 0; $i < sizeof( $array ); $i++ )
if( is_array( $array[$i] ) ) $ret[] = implode_md( $glue, $array[$i], $key, $list );
else $ret[] = $array[$i];
return implode( $glue, $ret );
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 128.123.203.0
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- https://master.php.net/note/edit/81215
Del: integrated -- https://master.php.net/note/delete/81215/integrated
Del: useless -- https://master.php.net/note/delete/81215/useless
Del: bad code -- https://master.php.net/note/delete/81215/bad+code
Del: spam -- https://master.php.net/note/delete/81215/spam
Del: non-english -- https://master.php.net/note/delete/81215/non-english
Del: in docs -- https://master.php.net/note/delete/81215/in+docs
Del: other reasons-- https://master.php.net/note/delete/81215
Reject -- https://master.php.net/note/reject/81215
Search -- https://master.php.net/manage/user-notes.php