While you’re all here, the topic continues: convert the array to a variable
Folk, is there an advanced version of the implode function for associative arrays?
For example:
$cars = array('van'=>'volvo xc70','coupe'=>'mercedes clk gtr','suv'=>'nissan pathfinder'); $glue1 = '<br />'; $glue2 = ' - '; extended_implode($glue1,$glue2,$cars);
Conclusion:
van - volvo xc70<br /> coupe - mercedes clk gtr<br /> suv - nissan pathfinder<br />
NB: If there is no regular function, I personally do not need an algorithm. =) So in this case, the question changes to "what mistakes are in my method".
function mb_extended_implode($glue1,$glue2,$elements,$enc='utf-8'){ $out = ''; foreach($elements as $key=>$value){ $out .= $key.$glue2.$value.$glue1; } $out = mb_substr($out,0,mb_strlen($glue2,$enc),$enc); return $out; }