-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathqueue.php
More file actions
61 lines (52 loc) · 1.14 KB
/
Copy pathqueue.php
File metadata and controls
61 lines (52 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
function writeToQueue($input){
$output = "";
$output .= "<?php ";
$output .= "return [";
foreach($input as $value){
$output .= '"' . $value . '",' ;
}
$output .= "] ";
$output .= "?>";
$myfile = fopen("queue_1.php", "w+") or die("Unable to open file!");
fwrite($myfile, $output);
fclose($myfile);
}
function getQueue(){
$baseQueue = include "queue_1.php";
if(count($baseQueue) <= 0){
$baseQueue = [];
}
return $baseQueue;
}
function addToQueue($value){
$queue = getQueue();
array_push($queue,$value); // push into the array
var_dump($queue); // see results
writeToQueue($queue);
return getQueue(); // return the current results
}
// lifo
function getLastItem(){
$queue = getQueue();
$value = array_pop($queue);
writeToQueue($queue);
return $value;
}
// fifo function
function getFirstItem(){
$queue = getQueue();
$value = array_shift($queue);
writeToQueue($queue);
return $value;
}
function emptyQueue(){
writeToQueue([]);
}
function isQueueEmpty(){
$queue = getQueue();
if(count($queue) <= 0){
return true;
}
return false;
}