Skip to content

Instantly share code, notes, and snippets.

@bkilshaw
Created January 21, 2011 22:09
Show Gist options
  • Save bkilshaw/790525 to your computer and use it in GitHub Desktop.
Save bkilshaw/790525 to your computer and use it in GitHub Desktop.
<?php // BRAD
$numbers = array("1", "2", "3", "4", "5");
function array_print($values) {
$array = array_reverse($values);
print_values($array);
}
function print_values($array) {
echo array_pop($array);
if(empty($array)) {
print_values($array);
}
}
array_print($numbers);
?>
<?php // TJ
$numbers = array("1", "2", "3", "4", "5");
a:
if (empty($numbers)) exit("Done.");
echo array_pop($numbers);
goto a;
?>
<?php // BRAD
if($_GET['array']) {
$array = unserialize($_GET['array']);
} else {
$array = array("1", "2", "3", "4", "5");
}
if($_GET['string']) {
$string = unserialize($_GET['string']);
} else {
$string = "";
}
if($_GET['current']) {
$current = $_GET['current'];
} else {
$current = 0;
}
if($_GET['stop']) {
$stop = $_GET['stop'];
} else {
$stop = count($array) - 1;
}
if($current <= $stop) {
$string .= "{$array[$current]} ";
$current += 1;
$array_serialized = serialize($array);
$string_serialized = serialize($string);
header("Location: {$_SERVER['PHP_SELF']}?array=$array_serialized&string=$string_serialized&current=$current&stop=$stop");
} else {
echo $string;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment