note 70165 added to function.implode

From: Date: Thu, 05 Oct 2006 09:11:33 +0000
Subject: note 70165 added to function.implode
Groups: php.notes 
Request: Send a blank email to php-notes+get-118083@lists.php.net to get a copy of this message
Very simple function for imploding a certain column in a 2D array. Useful if you have fetched records from a database in an associative array and want to store all the values in a certain column as a string, for use with JavaScript or passing values from page to page. $sep = the separator, such as " ", "," or "&amp;" $array = the 2D associative array $key = the column key, such as "id" Feel free to add error protection function implodeArray2D ($sep, $array, $key) { $num = count($array); $str = ""; for ($i = 0; $i < $num; $i++) { if ($i) { $str .= $sep; } $str .= $array[$i][$key]; } return $str; } ---- Server IP: 85.116.0.130 Probable Submitter: 88.109.66.180 ---- Manual Page -- http://www.php.net/manual/en/function.implode.php Edit -- https://master.php.net/note/edit/70165 Del: integrated -- https://master.php.net/note/delete/70165/integrated Del: useless -- https://master.php.net/note/delete/70165/useless Del: bad code -- https://master.php.net/note/delete/70165/bad+code Del: spam -- https://master.php.net/note/delete/70165/spam Del: non-english -- https://master.php.net/note/delete/70165/non-english Del: in docs -- https://master.php.net/note/delete/70165/in+docs Del: other reasons-- https://master.php.net/note/delete/70165 Reject -- https://master.php.net/note/reject/70165 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118083) next »