note 37262 deleted from function.join by vincent

From: Date: Fri, 07 Nov 2003 21:22:37 +0000
Subject: note 37262 deleted from function.join by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60123@lists.php.net to get a copy of this message
Note Submitter: chris@hitcatcher.com ---- I found it neccesary to create a function that joins the contents of a single dimension from a 2-d array. Here's the code in case anyone else should need to do the same: <?php function join_2d($glue, $pieces, $dimension = 0){ //joins the values of a single dimension in a 2-d array $rtn = array(); foreach($piece as $key => $value){ if(isset($value[$dimension])){ $rtn[] = $value[$dimension]; } } return join($glue, $rtn); } ?> The dimension argument can be a positive integer or a named index. Here is an example: <?php $testarray = array(array(1 => 'a', 'three' => 1), array(1 => 'b', 'three' => 2), array(1 => 'c', 'three' => 3), array(1 => 'd', 'three' => 4), array(1 => 'e', 'three' => 5)); print "<pre>"; print_r($testarray); print "</pre>"; print join_keys(", ", $testarray, 1) . "<br>"; print join_keys(", ", $testarray, 'three') . "<br>"; ?>

« previous php.notes (#60123) next »