Implode On Array Item Key


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function implode_on_key($array, $key, $sep, $prefix = '') {
  2. $string = '';
  3.  
  4. if(empty($array)) return '';
  5.  
  6. foreach($array as $element) {
  7. $string .= $prefix.$element[$key].$sep;
  8. }
  9.  
  10. return substr($string, 0, -strlen($sep));
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.