Skip to content

Instantly share code, notes, and snippets.

@ogredude
Created May 30, 2012 23:39
Show Gist options
  • Select an option

  • Save ogredude/09cf0ba5a6f1f90620f5 to your computer and use it in GitHub Desktop.

Select an option

Save ogredude/09cf0ba5a6f1f90620f5 to your computer and use it in GitHub Desktop.
<?php
function array_to_english ( $list, $glueword='and' ) {
$string = false;
foreach ( array_reverse ( $list ) as $index=>$value ) {
$string = "$value$glue$string";
if ( $index == 0 ) $glue = " $glueword ";
if ( $index == 1 ) $glue = ', ';
}
return $string;
}
function field_value($field, $inline = FALSE) {
$result = "";
if(count($field) > 1) {
if($inline) {
$values = array();
foreach ($field as $item) {
$values[] = $item['value'];
}
dpm($values);
$result = array_to_english($values);
} else {
$result = "<ul>";
foreach ($field as $item) {
$result .= "<li>" . $item['value'] . "</li>";
}
$result .= "</ul>";
}
} else if(count($field) == 1) {
$result = $field[0]['value'];
} else if (count($field) == 0) {
$result = "UNSET";
}
return $result;
}
//we include the helper.inc somewhere along the line up here.
/*
* Much stuff goes here
*/
<p>The business strategy is derived from offering the best <?php echo field_value($field_bp_market_strategy, 'inline'); ?>.</p>
<p>These strategies will be accomplished by <?php echo field_value($field_bp_strategy_plan); ?>. </p>
<p>A part of our business strategy involved educating ourselves about the competition. The top competitors are <?php echo field_value($field_bp_top_competitors, 'inline'); ?> Their market strategies are <?php echo field_value($field_bp_competitor_strategy, 'inline'); ?> which are different from <?php echo field_value($field_bp_business_name); ?>'s.
<?php
require('./sites/default/modules/ps1224_glue/helpers/business_plan_helper.inc');
$myarr = array('foo', 'bar', 'baz');
print array_to_english($myarr);
//prints correct "foo, bar, and baz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment