note 45667 added to function.implode

From: Date: Tue, 14 Sep 2004 18:45:20 +0000
Subject: note 45667 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-76684@lists.php.net to get a copy of this message
Chris Ross (17-Aug-2004 11:18) gave us a great function 'implode_assoc'. But it didn't handle multi-level array. I know, a few others here added this "feature", but... I've modified Chirs' function to be recursive. Hope it helps someone. /** * Method to recursivly implode a multi-dimensional array * Orginal: Chris Ross - 17-Aug-2004 * Modified: Walter Torres - 09-14-2004 **/ function implode_assoc_r($inner_glue = "=", $outer_glue = "\n", $array = null, $keepOuterKey = false) { $output = array(); foreach( $array as $key => $item ) if ( is_array ($item) ) { if ( $keepOuterKey ) $output[] = $key; // This is value is an array, go and do it again! $output[] = implode_assoc_r ($inner_glue, $outer_glue, $item, $keepOuterKey); } else $output[] = $key . $inner_glue . $item; return implode($outer_glue, $output); } ---- Manual Page -- http://www.php.net/manual/en/function.implode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45667 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45667&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45667&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76684) next »