Skip to content

Commit

Permalink
New function wfx_array_to_delimited_string()
Browse files Browse the repository at this point in the history
Builds a text string from a basic array - separates each value with an optional delimiter (but not the last one!)
  • Loading branch information
Jonnyauk committed Feb 12, 2014
1 parent e4bb36e commit d140d8a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
20 changes: 20 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,26 @@
} endif;


/**
* @since 1.1
* @updated 1.1
* Builds a text string from a basic array
* Separates each value with an optional delimiter (but not the last one!)
*/
if ( !function_exists( 'wfx_array_to_delimited_string' ) ) : function wfx_array_to_delimited_string($args) {

$echo = (isset($args['echo']) && $args['echo'] == 'Y') ? 'Y' : 'N';

global $wfx;
if ($echo == 'Y') {
echo $wfx->array_to_delimited_string($args);
} else {
return $wfx->array_to_delimited_string($args);
}

} endif;


//// 5 //////////// SOCIAL FUNCTIONS


Expand Down
43 changes: 43 additions & 0 deletions wf-includes/wf-display-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,49 @@ function wf_build_hyperlink($args){
}


/**
*
* Builds a text string from a basic array
* Separates each value with an optional delimiter (but not the last one!)
*
* @since 1.1
* @updated 1.1
*
* @param $values | array | REQUIRED | Basic array of values
* @param $seperator | string | optional | What you want in-between each item in array
* @param $start | string | optional | Text string at start of array
* @param $end | string | optional | Text string at end of array
*
*/
function wf_array_to_delimited_string($args){

$defaults = array (
'values' => '',
'seperator' => ', ',
'start' => '',
'end' => ''
);

$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );

if ( !is_array($values) ) return;

$count_all = count($values);
$counter = 1;
$output = '';

foreach( $values as $key => $value ) {
$output .= $value;
$output .= ( $counter != $count_all ) ? $seperator : '';
$counter++;
}

return esc_html($start.$output.$end);

}


}


Expand Down
1 change: 1 addition & 0 deletions wf-includes/wf-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function get_attachments($args){ return $this->wflux_display_ex_do->wf_get_attac
function page_counter($args){ return $this->wflux_display_ex_do->wf_page_counter($args); }
function get_cached_part($args){ return $this->wflux_display_ex_do->wf_get_cached_part($args); }
function build_hyperlink($args){ return $this->wflux_display_ex_do->wf_build_hyperlink($args); }
function array_to_delimited_string($args){ return $this->wflux_display_ex_do->wf_array_to_delimited_string($args); }

// Social functions
function g_plus_1($args){ return $this->wflux_display_social_do->wf_g_plus_1($args); }
Expand Down

0 comments on commit d140d8a

Please sign in to comment.