For example
1. There are 5 items A, B, C, D, E, one of which will be displayed in one or more locations of the Web page.
2. When the first visitor visits the page, he sees a content, and when the visitor opens the page again, he sees content a, unless he clears the browser cache.
3. When the second visitor visits the page, he sees the B content, and when the visitor opens the page again, he sees content B unless he clears the browser cache.
4 、。。。
5, the sixth visitor to visit the page, see a content, in the future when the visitor opens this page, see is content a, unless he clears the browser cache.
6, the seventh visitor to the page, see the B content, in the future when the visitor opens the page, will see the content B, unless he clears the browser cache.
Like some loops
It is equivalent to each visitor from 5 content in order to take a display to the visitor, complete 5 after the loop.
How do you write the code for this function?
Reply to discussion (solution)
Save with cookies
$arr = Array (' A ', ' B ', ' C ', ' D ', ' E '), $file = ' data.log ';//Gets the page that is not displayed, if all is displayed, then re-assign if (file_exists ($file)) { $data = Json_decode (file_get_contents ($file), true); if (! $data) { $data = $arr; }} else{ $data = $arr;} Determine if the user has visited, such as the direct display of the last access results, or extract the first page, write user cookiesif (Isset ($_cookie[' show ')) { $result = $_cookie[' show '];} else{ $result = Array_splice ($data, 0,1); $result = Array_pop ($result); Setcookie (' Show ', $result, Time () +3600); File_put_contents ($file, Json_encode ($data), true);} echo $result;