Skip to content

Instantly share code, notes, and snippets.

@tamouse
Created May 30, 2012 23:50
Show Gist options
  • Save tamouse/2839634 to your computer and use it in GitHub Desktop.
Save tamouse/2839634 to your computer and use it in GitHub Desktop.
<?php
error_reporting(-1);
ini_set('display_errors',true);
ini_set('display_startup_errors',true);
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;
}
$a=array('one','two','three','last');
echo array_to_english($a);
-*- mode: compilation; default-directory: "~/Projects/scratch/" -*-
Compilation started at Wed May 30 18:46:08
php a2eng.php
PHP Notice: Undefined variable: glue in /Users/tamara/Projects/scratch/a2eng.php on line 12
Notice: Undefined variable: glue in /Users/tamara/Projects/scratch/a2eng.php on line 12
one, two, three and last
Compilation finished at Wed May 30 18:46:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment