Skip to content
Browse files

Array_to_str, improved implode() native function

  • Loading branch information...
1 parent 71ac7e6 commit 8066cd94f081fac2c8f134db6e3ff87f29ff23ba @dixy committed Oct 4, 2011
Showing with 38 additions and 0 deletions.
  1. +38 −0 system/helpers/array_helper.php
View
38 system/helpers/array_helper.php
@@ -102,5 +102,43 @@ function elements($items, $array, $default = FALSE)
}
}
+// --------------------------------------------------------------------
+
+/**
+ * Array to string - Join array elements with a string.
+ *
+ * @access public
+ * @param array
+ * @param string
+ * @param string
+ * @return string
+ */
+if ( ! function_exists('array_to_str'))
+{
+ function array_to_str($array, $sep = ', ', $sep_last = '')
+ {
+ $return = '';
+
+ if ( ! $array)
+ {
+ return '';
+ }
+
+ if ($sep_last)
+ {
+ $last_element = array_pop($array);
+
+ if ( ! count($array))
+ {
+ return $last_element;
+ }
+
+ return implode($sep, $array).$sep_last.$last_element;
+ }
+
+ return implode($sep, $array);
+ }
+}
+
/* End of file array_helper.php */
/* Location: ./system/helpers/array_helper.php */

0 comments on commit 8066cd9

Please sign in to comment.
Something went wrong with that request. Please try again.