I am suffering from Brain-Block, and can't figure out how to code this. I'll try and keep my explaination short.
What I am trying to do:
I have a weather website and I am trying to display the last 3 searches the visitor has made, using cookies to read in and store the data. I want to make sure that each of the last 3 searches displayed is unique, and not a duplicate. But I can't figure out the logic on how to go from cookie to cookie, writing the last visit in the appropriate cookie. I know this sounds simple, but it doesn't seem that way to me. Can anyone help? BTW, I would show you what I have, but I don't have any code yet to make this work, as I can't figure out where to start.
Brian
PHP Logic problem
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
As feyd pointed out, it'd be a simple:
Code: Select all
<?php
$results = array();
$i = 0;
while (count($results) < 3 && isSet($_COOKIE['searches'][$i+1])){
if(!in_array($_COOKIE['searches'][$i+1]),$results)){
$results[] = $_COOKIE['searches'][$i+1];
}
}
echo "<pre>";
print_r($results);
echo "</pre>";
?>