note 37262 added to function.join

From: Date: Fri, 07 Nov 2003 19:29:18 +0000
Subject: note 37262 added to function.join
Groups: php.notes 
Request: Send a blank email to php-notes+get-60115@lists.php.net to get a copy of this message
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>"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.join.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37262 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37262&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37262&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60115) next »