思路 :
生成两个栈($stack ,$stack_min ),往$stack塞数据($value)的时候 ,比较一下$value和$stack_min最上面的元素的大小,如果$value小,则压入$stack_min栈
<?php
$stack = new SplStack();
$stack_min = new SplStack();
$arr = [200, 5, 12, 90, 192, 99];
foreach ($arr as $key => $value) {
$stack->push($value);
$stack_min->rewind();
$current = $stack_min->current();
if ($current === null) {
$stack_min->push($value);
}
if ($current >= $value) {
$stack_min->push($value);
}
}
echo $stack->count();
echo $stack_min->count();