note 96100 modified in function.implode by danbrown

From: Date: Tue, 09 Feb 2010 01:38:25 +0000
Subject: note 96100 modified in function.implode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165772@lists.php.net to get a copy of this message
Recursive Implode <?php function r_implode( $glue, $pieces ) { foreach( $pieces as $r_pieces ) { if( is_array( $r_pieces ) ) { $retVal[] = r_implode( $glue, $r_pieces ); } else { $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } $test_arr = array( 0, 1, array( 'a', 'b' ), array( array( 'x', 'y'), 'z' ) ); echo r_implode( ',', $test_arr ) . "\n"; $test_arr = array( 0 ); echo r_implode( ',', $test_arr ) . "\n"; ?> --was-- Recursive Implode <? function r_implode( $glue, $pieces ) { foreach( $pieces as $r_pieces ) { if( is_array( $r_pieces ) ) { $retVal[] = r_implode( $glue, $r_pieces ); } else { $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } $test_arr = array( 0, 1, array( 'a', 'b' ), array( array( 'x', 'y'), 'z' ) ); echo r_implode( ',', $test_arr ) . "\n"; $test_arr = array( 0 ); echo r_implode( ',', $test_arr ) . "\n"; ?> http://php.net/manual/en/function.implode.php

« previous php.notes (#165772) next »