PHP code example of chroma-x / stack-util
1. Go to this page and download the library: Download chroma-x/stack-util library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chroma-x / stack-util example snippets {php}
{php}
use ChromaX\StackUtil\Stack;
$stack = new Stack();
$stack
->push('Item')
->push('Another item')
->push(12)
->push(null)
->push(8.12);
$stackSize = $stack->size();
echo 'Stack size: ' . $stackSize . PHP_EOL;
{php}
$lastItem = $stack->get();
echo 'Last item: ' . $lastItem . PHP_EOL;
{php}
$secondItem = $stack->get(1);
echo 'Second item: ' . $secondItem . PHP_EOL;
{php}
$poppedItem = $stack->pop();
echo 'Popped item: ' . $poppedItem . PHP_EOL;
$stackSize = $stack->size();
echo 'Stack size: ' . $stackSize . PHP_EOL;
{php}
$lastItem = $stack
->set('9.12')
->get();
echo 'Updated last item: ' . $lastItem . PHP_EOL;
{php}
$thirdItem = $stack
->set('Third item', 2)
->get(2);
echo 'Updated third item: ' . $thirdItem . PHP_EOL;
{php}
echo 'Stack size: ' . $stack->size() . PHP_EOL;
$stack->delete(1);
echo 'Stack size: ' . $stack->size() . PHP_EOL;
{php}
foreach ($stack as $stackItemKey => $stackItemValue) {
echo 'Stack item ' . $stackItemKey . ': ' . $stackItemValue . PHP_EOL;
}
{php}
for ($i = 0, $n = $stack->size(); $i < $n; $i++) {
echo 'Stack index ' . $i . ': ' . $stack->get($i) . PHP_EOL;
}