Skip to content

Instantly share code, notes, and snippets.

@varemenos
Created March 17, 2012 16:05
Show Gist options
  • Save varemenos/2061506 to your computer and use it in GitHub Desktop.
Save varemenos/2061506 to your computer and use it in GitHub Desktop.
PHP - Array as Stack
<?php
$a = array();
for ($i=0; $i < 3; $i++) {
array_push($a, $i);
var_dump($a);
}
for ($i=0; $i < 3; $i++) {
array_pop($a);
var_dump($a);
}
// RESULTS
/*
array
0 => int 0
array
0 => int 0
1 => int 1
array
0 => int 0
1 => int 1
2 => int 2
array
0 => int 0
1 => int 1
array
0 => int 0
array
empty
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment