$ll = array();
for($i=0;$i<count($arr);$i++) {
        list($o, $n) = explode(" ", trim($arr[$i]));
        switch($o) {
                case "insert":
                        array_unshift($ll, $n);
                        break;
                case "delete":
                        for($j=0;$j<count($ll);$j++) {
                                if ($ll[$j]==$n) unset($ll[$j]);
                        }
                        break;
                case "deleteFirst":
                        array_shift($ll);
                        break;
                case "deleteLast":
                        array_pop($ll);
                        break;
        }
}
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.