Skip to content

Commit

Permalink
Array_to_str, improved implode() native function
Browse files Browse the repository at this point in the history
  • Loading branch information
dixy committed Oct 4, 2011
1 parent 8706a5d commit ce0f74b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions system/helpers/array_helper.php
Expand Up @@ -115,5 +115,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 ce0f74b

Please sign in to comment.