Based on Raphael_ code and your question you can try this:

    &lt;?php
            $aClicks = $this-&gt;session
                -&gt;userdata('article_clicks');
        $nextId = $this-&gt;session-&gt;userdata('nextId');
        // Initialize the array, if it's not already initialized
        if ($aClicks == false) {
            $aClicks = array();
            $nextId = 0;
        }
        // Now, we clean our array for the articles that have been clicked longer than
       // 10 minutes ago.
        $aClicks = array_filter($aClicks, function($click) {
                    return (time() - $click['time']) &lt; 600; // Less than 10 minutes elapsed
                }
        );
// We check if the article clicked is already in the list
        $found = false;
        foreach ($aClicks as $click) {
            if ($click['article'] === $id) { // Assuming $id holds the article id
                $found = true;
                break;
            }
        }
// If it's not, we add it
        if (!$found) {
            $aClicks[$nextId] = array(
                'article' =&gt; $id, // Assuming $id holds the article id
                'time' =&gt; time()
            );
            $nextId++;
            $this-&gt;session-&gt;set_userdata('nextId', $nextId);
        }
        $this-&gt;session-&gt;set_userdata('article_clicks', $aClicks);
        if (count($aClicks) &gt; 10 &amp;&amp; $nextId &gt; 9) {
            $this-&gt;session-&gt;set_userdata('nextId', 0);
            echo "OK!";

        }
    ?&gt;


How to remember 10 last read articles with timestamp in session for a user in Codeigniter?
I have enum list and method and i get error: " not all code paths return a value"
Some idea whats wrong in my method ? I am sure I always return STANY type :/

Thanks for help :)

     private enum STANY { PATROL, CHAT, EAT, SEARCH, DIE };

     private STANY giveState(int id, List&lt;Ludek&gt; gracze, List&lt;int&gt; plansza)
    {
        // Sprawdz czy gracz stoi na polu z jedzeniem i nie ma 2000 jednostek jedzenia
        bool onTheFood = false;
        onTheFood = CzyPoleZjedzeniem(id, gracze, plansza, onTheFood);

        if (onTheFood &amp;&amp; (gracze[id].IloscJedzenia &lt; startFood / 2))
            return STANY.EAT;

        // Sprawdz czy gracz nie stoi na polu z innym graczem
        bool allKnowledge = true;
        allKnowledge = CzyPoleZInnymGraczem(id, gracze, allKnowledge);

        if (!allKnowledge)
            return STANY.CHAT;

        // Jesli ma ponad i rowna ilosc jedzenia patroluj
        if (gracze[id].IloscJedzenia &gt;= startFood / 2)
            return STANY.PATROL;

        // Jesli ma mniej niz polowe jedzenia szukaj jedzenia
        if (gracze[id].IloscJedzenia &gt; 0 &amp;&amp; gracze[id].IloscJedzenia &lt; startFood / 2)
            return STANY.SEARCH;

        // Jesli nie ma jedzenia umieraj
        if (gracze[id].IloscJedzenia &lt;= 0)
            return STANY.DIE;
    }

