<?php
class
Queue {
public
$length
=12;
public
$queue
=
array
();
public
$delimiter
=
','
;
function
__construct(
$queue
=
array
())
{
$this
->queue=
$queue
;
}
public
function
run(
$param
)
{
if
(!
is_array
(
$this
->queue)){
$this
->strToQue();
}
$currentlength
=
$this
->countqueue();
if
(
$currentlength
<
$this
->length&&
$this
->length>0) {
$this
->queAdd(
$param
);
}
else
if
(
$this
->length=0)
{
$this
->queue[]=
$param
;
}
else
{
$this
->queRemove();
$this
->queAdd(
$param
);
}
return
$this
->queue;
}
public
function
strToQue (){
if
(
empty
(
$this
->queue))
{
$this
->queue=
array
();
}
else
{
$this
->queue=
explode
(
$this
->delimiter,
$this
->queue);
}
}
private
function
queAdd(
$node
){
array_push
(
$this
->queue,
$node
);
$this
->countqueue();
}
private
function
queRemove(){
$node
=
array_shift
(
$this
->queue);
$this
->countqueue();
return
$node
;
}
private
function
countqueue(){
$currentlength
=
count
(
$this
->queue);
return
$currentlength
;
}
function
__destruct()
{
unset(
$this
->queue);
}
}
$str
=
''
;
$obj
=
new
Queue (
$str
);
$obj
->length=8;
$obj
->delimiter=
'|'
;
$a
=
$obj
->run(
'91'
);
$a
=
$obj
->run(
'92'
);
$a
=
$obj
->run(
'93'
);
$a
=
$obj
->run(
'94'
);
print_r(
$a
);
?>