note 70165 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:17:32 +0000
Subject: note 70165 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189735@lists.php.net to get a copy of this message
Note Submitter: Demonisch ---- 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; }

« previous php.notes (#189735) next »