1

I'm trying to return the values of a session array (productsviewed) which I have working using the following code:

    $val=$ProdGrp;
   array_push($_SESSION[productsviewed],$val);
   //print_R($_SESSION[productsviewed]);
        foreach (array_unique($_SESSION[productsviewed]) as $result) {
        //echo $result."<br>\n";
        }

where $ProdGrp is the 'product code' and each new item is added to the array when a new page viewed without creating duplicates - this all works fine!

However, I would like to limit the number of results returned to the last 5 items viewed.

Is it possible to combine this code with array_slice to come up with the result?

Thanks in advance for any pointers :)

0 Answers0